From fb2e7cda361967fb64d12e2a162c47d289d744bb Mon Sep 17 00:00:00 2001 From: hq1 Date: Mon, 16 Dec 2024 12:39:36 +0100 Subject: [PATCH] Flaky test: wait till lock is acquired (#4903) --- test/plausible/ingestion/event_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/plausible/ingestion/event_test.exs b/test/plausible/ingestion/event_test.exs index bc9d98b6cc6d..e19d1da1174b 100644 --- a/test/plausible/ingestion/event_test.exs +++ b/test/plausible/ingestion/event_test.exs @@ -280,7 +280,10 @@ defmodule Plausible.Ingestion.EventTest do test "drops events on session lock timeout" do site = new_site() + test = self() + very_slow_buffer = fn sessions -> + send(test, :slow_buffer_insert_started) Process.sleep(1000) Plausible.Session.WriteBuffer.insert(sessions) end @@ -310,10 +313,11 @@ defmodule Plausible.Ingestion.EventTest do ) end) - Process.sleep(200) - - assert {:ok, %{buffered: [], dropped: [dropped]}} = Event.build_and_buffer(second_request) - assert dropped.drop_reason == :lock_timeout + receive do + :slow_buffer_insert_started -> + assert {:ok, %{buffered: [], dropped: [dropped]}} = Event.build_and_buffer(second_request) + assert dropped.drop_reason == :lock_timeout + end end test "drops pageleave event when no session found from cache" do