Repository navigation
Fix flaky test - #3626
Fix flaky test#3626
Conversation
| describe "collapse order" do | ||
| defp new_site_id() do | ||
| [[site_id]] = | ||
| Plausible.ClickhouseRepo.query!("select max(site_id) + rand() from sessions_v2 FINAL").rows |
There was a problem hiding this comment.
I guess max(site_id) + 1 works just as good. Not sure.
There was a problem hiding this comment.
Can it be part of the fixtures? Is the query expensive?
There was a problem hiding this comment.
Otherwise we can use the same approach as all the other tests use, a custom large int for site_id.
There was a problem hiding this comment.
Can it be part of the fixtures? Is the query expensive?
I'll check 👍
Otherwise we can use the same approach as all the other tests use, a custom large int for site_id.
What do you mean? Which approach? Random ints we currently use are clearly prone to clashing.
There was a problem hiding this comment.
build(:event, name: "pageview", site_id: 123784652187346)
https://github.com/search?q=repo%3Aplausible%2Fanalytics%20%40site_id&type=code
https://github.com/search?q=repo%3Aplausible%2Fanalytics+%40user_id&type=code
There was a problem hiding this comment.
Can it be part of the fixtures? Is the query expensive?
Finished in 41.2 seconds (13.7s async, 27.4s sync)
9 doctests, 1937 tests, 0 failures, 29 excluded
vs
Finished in 116.0 seconds (69.3s async, 46.7s sync)
9 doctests, 1937 tests, 2 failures, 29 excluded
Clearly not worth it, this workaround is again, specific to that test.
There was a problem hiding this comment.
I guess it's fine if it works, sorry to be nit-picky :)
Another idea I had was to use System.unique_integer([:positive]) but since it can overlap with sites.id from PostgreSQL, I'd read the current sequence value for sites and add a million (a number large enough to cover all sites inserted into PostgreSQL during the test run) and then add System.unique_integer([:positive]) to ensure uniqueness in ClickHouse-only tests. And that would be used in fixtures, since the cost is static (select nextval('sites_id_seq') from PostgreSQL or something, in test_helpers.exs).
There was a problem hiding this comment.
# test_helpers.exs, there might be a better place to put it than app env
[[min_sites_id]] = Plausible.Repo.query!("select nextvar('sites_id_seq')").rows
Application.put_env(:plausible, :tests, min_sites_id: min_sites_id)
# fixtures
def event do
# ...
site_id: Keyword.fetch!(Application.fetch_env!(:plausible, :tests), :min_sites_id) + 1_000_000 + System.unique_integer([:positive])
# ...
endThere was a problem hiding this comment.
application env is another shared state we're suffering from, I'm gonna just go ahead and merge it
Changes
The test flakiness introduced via #3622 was reproducible locally by running the
across partstests hundred times with a macro generator. This patch no longer leads to failures.Tests
Changelog
Documentation
Dark mode