Skip to content

add session collapse order test - #3622

Merged
aerosol merged 1 commit into
plausible:masterfrom
ruslandoga:session-insert-order-test
Dec 13, 2023
Merged

aerosol merged 1 commit into
plausible:masterfrom
ruslandoga:session-insert-order-test

Conversation

@ruslandoga

@ruslandoga ruslandoga commented Dec 13, 2023 •

Copy link
Copy Markdown
Contributor

Changes

This PR adds tests to ensure the correct session collapse order. It should prevent issues similar to #3511 (comment)

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@ruslandoga
ruslandoga requested a review from a team December 13, 2023 05:17
@ruslandoga
ruslandoga force-pushed the session-insert-order-test branch 7 times, most recently from e61f7bf to a1f96ac Compare December 13, 2023 06:09
@ruslandoga
ruslandoga force-pushed the session-insert-order-test branch from a1f96ac to 5a044a6 Compare December 13, 2023 06:15
assert session.exit_page == "/exit"
end

test "within parts" do

@ruslandoga ruslandoga Dec 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

within parts test is not strictly required since ClickHouse is smart enough to fix the ordering within a single part but I'm including it for completeness.

assert session.duration == 10
end

describe "collapse order" do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To make the tests fail, reverse the order in Plausible.Session.CacheStore.on_event

buffer.insert([%{updated_session | sign: 1}, %{found_session | sign: -1}])

- buffer.insert([%{updated_session | sign: 1}, %{found_session | sign: -1}])
+ buffer.insert([%{found_session | sign: -1}, %{updated_session | sign: 1}])

@aerosol
aerosol merged commit 95e7a2b into plausible:master Dec 13, 2023
@aerosol

aerosol commented Dec 13, 2023

Copy link
Copy Markdown
Member

The test seems flaky:

  1) test collapse order across parts (Plausible.Session.CacheStoreTest)
Error:      test/plausible/session/cache_store_test.exs:126
     ** (Ecto.MultipleResultsError) expected at most one result but got 2 in query:
     
     from c0 in Plausible.ClickhouseSessionV2,
       where: c0.site_id == ^1449
     
     code: session = Plausible.ClickhouseRepo.one!(session_q, settings: [final: true])
     stacktrace:
       (ecto 3.10.3) lib/ecto/repo/queryable.ex:162: Ecto.Repo.Queryable.one!/3
       test/plausible/session/cache_store_test.exs:133: (test)

--max-failures reached, aborting test suite
Finished in 90.6 seconds (45.7s async, 44.9s sync)
9 doctests, 1899 tests, 1 failure, 11 excluded

Randomized with seed 617323
Error: Process completed with exit code 2.

https://github.com/plausible/analytics/actions/runs/7192271123/job/19588394230


describe "collapse order" do
defp flush(events) do
for e <- events, do: CacheStore.on_event(e, nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe a separate buffer must be spawned for each test?

@ruslandoga ruslandoga Dec 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem doesn't seem to be with the buffer, but rather with the site_ids which are not unique. I'll need to check how they are generated.

@aerosol aerosol mentioned this pull request Dec 13, 2023
4 of 8 tasks
@ruslandoga
ruslandoga deleted the session-insert-order-test branch December 13, 2023 08:34
@aerosol aerosol mentioned this pull request Dec 13, 2023
4 of 8 tasks
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.

3 participants