From 033b2f2904743c1d47bf2c5e12c0e57661ff9685 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Wed, 29 Jan 2025 11:37:35 +0000 Subject: [PATCH] fix flaky integration test (#2775) (cherry picked from commit 8aee9495dbcb69703931814f116abce3ebf4e3f6) --- .../test_integration/test_examples/_async/test_vectors.py | 8 ++------ .../test_integration/test_examples/_sync/test_vectors.py | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/test_elasticsearch/test_dsl/test_integration/test_examples/_async/test_vectors.py b/test_elasticsearch/test_dsl/test_integration/test_examples/_async/test_vectors.py index 49c2c01da..dc45ceb52 100644 --- a/test_elasticsearch/test_dsl/test_integration/test_examples/_async/test_vectors.py +++ b/test_elasticsearch/test_dsl/test_integration/test_examples/_async/test_vectors.py @@ -22,7 +22,6 @@ import pytest from elasticsearch import AsyncElasticsearch -from test_elasticsearch.test_dsl.async_sleep import sleep from ..async_examples import vectors @@ -48,9 +47,6 @@ def encode(self, text: str) -> List[float]: mocker.patch.object(vectors, "SentenceTransformer", new=MockModel) await vectors.create() - for i in range(10): - results = await (await vectors.search("Welcome to our team!")).execute() - if len(results.hits) > 0: - break - await sleep(0.1) + await vectors.WorkplaceDoc._index.refresh() + results = await (await vectors.search("Welcome to our team!")).execute() assert results[0].name == "New Employee Onboarding Guide" diff --git a/test_elasticsearch/test_dsl/test_integration/test_examples/_sync/test_vectors.py b/test_elasticsearch/test_dsl/test_integration/test_examples/_sync/test_vectors.py index 2bfdce8c5..4b14c89a0 100644 --- a/test_elasticsearch/test_dsl/test_integration/test_examples/_sync/test_vectors.py +++ b/test_elasticsearch/test_dsl/test_integration/test_examples/_sync/test_vectors.py @@ -22,7 +22,6 @@ import pytest from elasticsearch import Elasticsearch -from test_elasticsearch.test_dsl.sleep import sleep from ..examples import vectors @@ -48,9 +47,6 @@ def encode(self, text: str) -> List[float]: mocker.patch.object(vectors, "SentenceTransformer", new=MockModel) vectors.create() - for i in range(10): - results = (vectors.search("Welcome to our team!")).execute() - if len(results.hits) > 0: - break - sleep(0.1) + vectors.WorkplaceDoc._index.refresh() + results = (vectors.search("Welcome to our team!")).execute() assert results[0].name == "New Employee Onboarding Guide"