Address flakiness in ingest counter tests

This commit is contained in:
Adrian Gruntkowski 2024-12-11 21:59:57 +01:00
parent 6ea8758f46
commit 60dc1e4115
2 changed files with 18 additions and 5 deletions

View File

@ -145,14 +145,20 @@ defmodule Plausible.Ingestion.CountersTest do
r.value == ^value
)
query =
count =
if site_id do
query |> where([r], r.site_id == ^site_id)
query
|> where([r], r.site_id == ^site_id)
|> await_clickhouse_count(1)
else
query |> where([r], is_nil(r.site_id))
# As null site_id entries might be added by parallel tests,
# we make the check more permissive in that case.
query
|> where([r], is_nil(r.site_id))
|> await_clickhouse_count(fn count -> count > 0 end)
end
assert await_clickhouse_count(query, 1)
assert count
end
defp random_domain() do

View File

@ -220,11 +220,18 @@ defmodule Plausible.TestUtils do
end
def await_clickhouse_count(query, expected) do
expect_fn =
if is_function(expected, 1) do
expected
else
fn count -> count == expected end
end
eventually(
fn ->
count = Plausible.ClickhouseRepo.aggregate(query, :count)
{count == expected, count}
{expect_fn.(count), count}
end,
500,
10