mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 17:11:36 +03:00
Address flakiness in ingest counter tests
This commit is contained in:
parent
6ea8758f46
commit
60dc1e4115
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user