|
3 | 3 | import boto3
|
4 | 4 | import botocore
|
5 | 5 | import pytest
|
| 6 | +from botocore.config import Config |
6 | 7 |
|
7 | 8 | from localstack.aws.api import RequestContext
|
8 | 9 | from localstack.aws.chain import Handler, HandlerChain
|
@@ -248,10 +249,44 @@ def test_client_caching(self):
|
248 | 249 | # TODO does it really make sense to test the caching?
|
249 | 250 | # TODO pretty ugly way of accessing the internal client
|
250 | 251 | factory = InternalClientFactory()
|
251 |
| - assert factory().s3._client == factory().s3._client |
| 252 | + assert factory().s3._client is factory().s3._client |
252 | 253 | factory_2 = InternalClientFactory()
|
253 | 254 | assert factory().s3._client != factory_2().s3._client
|
254 | 255 |
|
| 256 | + def test_client_caching_with_config(self): |
| 257 | + """Test client caching. Same factory for the same service should result in the same client. |
| 258 | + Different factories should result in different (identity wise) clients""" |
| 259 | + # This test might get flaky if some internal boto3 caching is introduced at some point |
| 260 | + config = Config(read_timeout=2, signature_version=botocore.UNSIGNED) |
| 261 | + second_config = Config(read_timeout=2, signature_version=botocore.UNSIGNED) |
| 262 | + third_config = Config(read_timeout=3, signature_version=botocore.UNSIGNED) |
| 263 | + factory = InternalClientFactory() |
| 264 | + client_1 = factory(config=config).s3._client |
| 265 | + client_2 = factory(config=config).s3._client |
| 266 | + client_3 = factory(config=second_config).s3._client |
| 267 | + client_4 = factory(config=third_config).s3._client |
| 268 | + assert client_1 is client_2 |
| 269 | + assert client_2 is client_3 |
| 270 | + assert client_3 is not client_4 |
| 271 | + |
| 272 | + def test_client_caching_with_merged_configs(self): |
| 273 | + """Test client caching. Same factory for the same service should result in the same client. |
| 274 | + Different factories should result in different (identity wise) clients""" |
| 275 | + # This test might get flaky if some internal boto3 caching is introduced at some point |
| 276 | + config_1 = Config(read_timeout=2) |
| 277 | + config_2 = Config(signature_version=botocore.UNSIGNED) |
| 278 | + config_3 = config_1.merge(config_2) |
| 279 | + config_4 = config_1.merge(config_2) |
| 280 | + factory = InternalClientFactory() |
| 281 | + client_1 = factory(config=config_1).s3._client |
| 282 | + client_2 = factory(config=config_2).s3._client |
| 283 | + client_3 = factory(config=config_3).s3._client |
| 284 | + client_4 = factory(config=config_4).s3._client |
| 285 | + assert client_1 is not client_2 |
| 286 | + assert client_2 is not client_3 |
| 287 | + assert client_1 is not client_3 |
| 288 | + assert client_3 is client_4 |
| 289 | + |
255 | 290 | def test_internal_request_parameters(self, create_dummy_request_parameter_gateway):
|
256 | 291 | internal_dto = None
|
257 | 292 |
|
|
0 commit comments