Skip to content

Fix test failing due to timestamp setup - #4562

Merged
zoldar merged 1 commit into
masterfrom
fix/time-related-test-fail
Sep 10, 2024
Merged

zoldar merged 1 commit into
masterfrom
fix/time-related-test-fail

Conversation

@zoldar

@zoldar zoldar commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

Changes

Today one test started consistently failing across local dev envs and CI:

   1) test GET /api/stats/:domain/sources order_by [[visit_duration, asc], [visit:source, desc]]] is respected and flipping the sort orders works (PlausibleWeb.Api.StatsController.SourcesTest)
Error:      test/plausible_web/controllers/api/stats_controller/sources_test.exs:544
     Assertion with == failed
     code:  assert json_response(conn1, 200)["results"] == [
              %{"name" => "Z", "visitors" => 1, "bounce_rate" => 100, "visit_duration" => 0},
              %{"name" => "A", "visitors" => 2, "bounce_rate" => 100, "visit_duration" => 0},
              %{"name" => "C", "visitors" => 1, "bounce_rate" => 0, "visit_duration" => 30},
              %{"name" => "B", "visitors" => 1, "bounce_rate" => 0, "visit_duration" => 45}
            ]
     left:  [
              %{
                "bounce_rate" => 100,
                "name" => "Z",
                "visit_duration" => 0,
                "visitors" => 1
              },
              %{
                "bounce_rate" => 100,
                "name" => "A",
                "visit_duration" => 0,
                "visitors" => 2
              }
            ]
     right: [
              %{
                "bounce_rate" => 100,
                "name" => "Z",
                "visit_duration" => 0,
                "visitors" => 1
              },
              %{
                "bounce_rate" => 100,
                "name" => "A",
                "visit_duration" => 0,
                "visitors" => 2
              },
              %{
                "bounce_rate" => 0,
                "name" => "C",
                "visit_duration" => 30,
                "visitors" => 1
              },
              %{
                "bounce_rate" => 0,
                "name" => "B",
                "visit_duration" => 45,
                "visitors" => 1
              }
            ]
     stacktrace:
       test/plausible_web/controllers/api/stats_controller/sources_test.exs:584: (test)

Ultimately it turned out the setup had part of events with timestamp setup explicitly to 2024-10-08 and part not, while the endpoint query used implicit date (today) and implicit period (last 30 days). Once the fixed timestamp entries went beyond 30 days since 2024-08-10, the test started failing. This PR changes the test to use fixed time consistently.

@zoldar
zoldar requested a review from a team September 10, 2024 10:26
@zoldar
zoldar merged commit c105ebc into master Sep 10, 2024
@zoldar
zoldar deleted the fix/time-related-test-fail branch September 10, 2024 10:30
@zoldar

zoldar commented Sep 10, 2024

Copy link
Copy Markdown
Contributor Author

Hah, actually got ninja'd at discovering what caused it by @ruslandoga with #4502 (comment) - just noticed now 😅

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