Skip to content

Fix flaky test - #3626

Merged
aerosol merged 2 commits into
masterfrom
guaranteed-unique-random-user-id-for-flaky-test
Dec 13, 2023
Merged

aerosol merged 2 commits into
masterfrom
guaranteed-unique-random-user-id-for-flaky-test

Conversation

@aerosol

@aerosol aerosol commented Dec 13, 2023

Copy link
Copy Markdown
Member

Changes

The test flakiness introduced via #3622 was reproducible locally by running the across parts tests hundred times with a macro generator. This patch no longer leads to failures.

Tests

  • Automated tests have been added
  • This PR does not require tests

Changelog

  • Entry has been added to changelog
  • This PR does not make a user-facing change

Documentation

  • Docs have been updated
  • This change does not need a documentation update

Dark mode

  • The UI has been tested both in dark and light mode
  • This PR does not change the UI

@aerosol
aerosol requested a review from ruslandoga December 13, 2023 09:30
describe "collapse order" do
defp new_site_id() do
[[site_id]] =
Plausible.ClickhouseRepo.query!("select max(site_id) + rand() from sessions_v2 FINAL").rows

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess max(site_id) + 1 works just as good. Not sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be part of the fixtures? Is the query expensive?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise we can use the same approach as all the other tests use, a custom large int for site_id.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ruslandoga ruslandoga Dec 13, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ruslandoga ruslandoga Dec 13, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@ruslandoga ruslandoga Dec 13, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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])
  # ...
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application env is another shared state we're suffering from, I'm gonna just go ahead and merge it

@aerosol
aerosol merged commit d161ad7 into master Dec 13, 2023
@aerosol
aerosol deleted the guaranteed-unique-random-user-id-for-flaky-test branch December 13, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants