From 96a804585cc2488aa663373a41f8794441d15021 Mon Sep 17 00:00:00 2001 From: Jan-Kazlouski-elastic Date: Fri, 4 Sep 2026 21:45:10 +0300 Subject: [PATCH] test(s3): mock AWS client in close-with-session test (#4442) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary `test_close_with_client_session` was making real AWS `ListBuckets` HTTP calls with dummy credentials. That caused slow, flaky failures under `--fail-slow=1` when network latency exceeded 1s. The test now mocks the S3 client (same pattern as `test_ping`) and asserts that `close()` tears down the `AsyncExitStack` used for the client session. ## Checklists #### Pre-Review Checklist - [x] this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check `config.yml.example`) - [x] this PR has a meaningful title - [x] this PR links to all relevant github issues that it fixes or partially addresses - [x] if there is no GH issue, please create it. Each PR should have a link to an issue - [x] this PR has a thorough description - [x] Covered the changes with automated tests - [x] Tested the changes locally - [ ] Added a label for each target release version (example: `v7.13.2`, `v7.14.0`, `v8.0.0`) - [ ] For bugfixes: backport safely to all minor branches still receiving patch releases - [x] Considered corresponding documentation changes - [x] Contributed any configuration settings changes to the configuration reference - [x] if you added or changed Rich Configurable Fields for a Native Connector, you made a corresponding PR in [Kibana](https://github.com/elastic/kibana/blob/main/packages/kbn-search-connectors/types/native_connectors.ts) #### Changes Requiring Extra Attention - [ ] Security-related changes (encryption, TLS, SSRF, etc) - [ ] New external service dependencies added. ## Related Pull Requests * https://github.com/elastic/connectors/pull/4441 — Outlook LDAP retry fix (where the flake was first observed) ## Release Note n/a — test-only change. Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor Co-authored-by: Elastic Machine --- app/connectors_service/NOTICE.txt | 2 +- app/connectors_service/tests/sources/test_s3.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/connectors_service/NOTICE.txt b/app/connectors_service/NOTICE.txt index 217aad009..67223f5e0 100644 --- a/app/connectors_service/NOTICE.txt +++ b/app/connectors_service/NOTICE.txt @@ -4241,7 +4241,7 @@ Apache Software License google-auth -2.57.0 +2.57.1 Apache Software License Apache License Version 2.0, January 2004 diff --git a/app/connectors_service/tests/sources/test_s3.py b/app/connectors_service/tests/sources/test_s3.py index 9eb01f897..4d8e50e61 100644 --- a/app/connectors_service/tests/sources/test_s3.py +++ b/app/connectors_service/tests/sources/test_s3.py @@ -494,14 +494,16 @@ async def test_get_content_with_clienterror(): @pytest.mark.asyncio async def test_close_with_client_session(): """Test close method of S3DataSource with client session""" - async with create_s3_source() as source: - source.session = aioboto3.Session() - await source.s3_client.client() - - await source.close() - with pytest.raises(ClientError): - await source.ping() + with ( + mock.patch("aiobotocore.client.AioBaseClient", S3Object), + mock.patch( + "contextlib.AsyncExitStack.aclose", new_callable=mock.AsyncMock + ) as aclose_mock, + ): + await source.s3_client.client() + await source.close() + aclose_mock.assert_awaited_once() @pytest.mark.parametrize(