From 1ec24bac5f9764a67ee15d37ceebc56a34fa12a9 Mon Sep 17 00:00:00 2001 From: gmega Date: Tue, 21 Jan 2025 19:18:29 -0300 Subject: [PATCH] fix: add synchronization predicates to ES fixtures --- benchmarks/logging/sources/tests/fixtures.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/benchmarks/logging/sources/tests/fixtures.py b/benchmarks/logging/sources/tests/fixtures.py index 9d2f903..7287e25 100644 --- a/benchmarks/logging/sources/tests/fixtures.py +++ b/benchmarks/logging/sources/tests/fixtures.py @@ -18,6 +18,9 @@ def _json_data(data: str) -> Dict[str, Any]: def benchmark_logs_client() -> Elasticsearch: client = Elasticsearch(os.environ.get("ELASTICSEARCH_URL", "http://localhost:9200")) + # ES may take a while to boot up. + await_predicate(client.ping, timeout=15, polling_interval=0.5) + if client.indices.exists(index="benchmarks-2025.01.21"): client.indices.delete(index="benchmarks-2025.01.21") @@ -33,6 +36,7 @@ def benchmark_logs_client() -> Elasticsearch: def _is_indexed() -> bool: return client.count(index="benchmarks-2025.01.21")["count"] == len(documents) + # Indexed documents may not be immediately visible, hence the wait. assert await_predicate( _is_indexed, timeout=10, polling_interval=0.5 ), "Indexing failed"