Skip to content

Stop cleaning cluster between rest_api_spec tests #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions test_elasticsearch_serverless/test_async/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@pytest_asyncio.fixture(scope="function")
async def async_client(elasticsearch_url, elasticsearch_api_key):
async def async_client_factory(elasticsearch_url, elasticsearch_api_key):

if not hasattr(elasticsearch_serverless, "AsyncElasticsearch"):
pytest.skip("test requires 'AsyncElasticsearch' and aiohttp to be installed")
Expand All @@ -37,10 +37,18 @@ async def async_client(elasticsearch_url, elasticsearch_api_key):
client = None
try:
client = elasticsearch_serverless.AsyncElasticsearch(
elasticsearch_url, api_key=elasticsearch_api_key, request_timeout=3
elasticsearch_url, api_key=elasticsearch_api_key
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the unrelated change, but a request timeout of 3 (instead of the default 10) can sometimes be too short on serverless.

)
yield client
finally:
if client:
wipe_cluster(client, elasticsearch_api_key)
await client.close()


@pytest.fixture(scope="function")
def async_client(async_client_factory, elasticsearch_api_key):
try:
yield async_client_factory
finally:
# Wipe the cluster clean after every test execution.
wipe_cluster(async_client_factory, elasticsearch_api_key)
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ async def _feature_enabled(self, name):


@pytest_asyncio.fixture(scope="function")
def async_runner(async_client):
return AsyncYamlRunner(async_client)
def async_runner(async_client_factory):
return AsyncYamlRunner(async_client_factory)


if RUN_ASYNC_REST_API_TESTS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ def _skip_intentional_type_errors(self, e: Exception):


@pytest.fixture(scope="function")
def sync_runner(sync_client):
return YamlRunner(sync_client)
def sync_runner(sync_client_factory):
return YamlRunner(sync_client_factory)


# Source: https://stackoverflow.com/a/37958106/5763213
Expand Down