From 1d683c4afd0d072602661ad41b0a9fd6ad72e948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Fri, 22 Sep 2023 15:26:58 +0200 Subject: [PATCH] fix: Wait for a few seconds in test --- .../api/test/batch_exports/test_log_entry.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/posthog/api/test/batch_exports/test_log_entry.py b/posthog/api/test/batch_exports/test_log_entry.py index 07a04112af9651..9aa0f924bd1dce 100644 --- a/posthog/api/test/batch_exports/test_log_entry.py +++ b/posthog/api/test/batch_exports/test_log_entry.py @@ -148,13 +148,20 @@ def test_log_level_filter(batch_export, team): BatchExportLogEntryLevel.ERROR, BatchExportLogEntryLevel.DEBUG, ): - results = fetch_batch_export_log_entries( - team_id=team.pk, - batch_export_id=batch_export["id"], - level_filter=[level], - after=dt.datetime(2023, 9, 22, 0, 59, 59), - before=dt.datetime(2023, 9, 22, 1, 0, 1), - ) + results = [] + timeout = 10 + start = dt.datetime.utcnow() + + while not results: + results = fetch_batch_export_log_entries( + team_id=team.pk, + batch_export_id=batch_export["id"], + level_filter=[level], + after=dt.datetime(2023, 9, 22, 0, 59, 59), + before=dt.datetime(2023, 9, 22, 1, 0, 1), + ) + if (dt.datetime.utcnow() - start) > dt.timedelta(seconds=timeout): + break results.sort(key=lambda record: record.message)