Skip to content

Commit d7ce88e

Browse files
committed
better tests, do not access internals that much
1 parent a9ed2b0 commit d7ce88e

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

tests/unit/storage_clients/test_alias_resolver.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_storage_key_format() -> None:
2828

2929
async def test_resolve_id_returns_none_for_unknown() -> None:
3030
"""Test that resolve_id returns None for an alias not in the map."""
31-
AliasResolver._alias_map = {}
3231
config = Configuration(token='test-token')
3332
resolver = AliasResolver(
3433
storage_type='Dataset', alias='unknown-alias', configuration=config, api_client=_api_client()
@@ -52,7 +51,6 @@ async def test_resolve_id_returns_stored_id() -> None:
5251

5352
async def test_store_mapping_local_only() -> None:
5453
"""Test that store_mapping only updates in-memory map when not at home."""
55-
AliasResolver._alias_map = {}
5654
config = Configuration(is_at_home=False, token='test-token')
5755
resolver = AliasResolver(
5856
storage_type='RequestQueue', alias='test-alias', configuration=config, api_client=_api_client()
@@ -66,8 +64,6 @@ async def test_store_mapping_local_only() -> None:
6664

6765
async def test_concurrent_alias_creation_uses_lock() -> None:
6866
"""Test that the context manager acquires and releases a lock."""
69-
AliasResolver._alias_init_lock = None
70-
AliasResolver._alias_map = {}
7167
config = Configuration(token='test-token')
7268
resolver = AliasResolver(storage_type='Dataset', alias='test', configuration=config, api_client=_api_client())
7369

@@ -153,29 +149,33 @@ async def test_configuration_storages_alias_resolving() -> None:
153149

154150

155151
def test_default_kvs_client_derives_from_injected_client() -> None:
156-
"""The default-KVS client used for alias mapping is derived from the injected client, not a freshly created one."""
157-
api_client = _api_client()
152+
"""The default-KVS client for alias mapping is built from the injected client, not a freshly created one."""
158153
config = Configuration(token='test-token', default_key_value_store_id='default-kvs-id')
154+
api_client = MagicMock()
159155
resolver = AliasResolver(storage_type='Dataset', alias='a', configuration=config, api_client=api_client)
160156

161157
kvs_client = resolver._get_default_kvs_client()
162158

163-
assert kvs_client.resource_id == 'default-kvs-id'
164-
# Shares the injected client's HTTP client (and its connection pool), proving no separate client is spun up.
165-
assert kvs_client._http_client is api_client.http_client
159+
# The KVS client comes straight from the injected client for the configured store, so no separate client is created.
160+
api_client.key_value_store.assert_called_once_with(key_value_store_id='default-kvs-id')
161+
assert kvs_client is api_client.key_value_store.return_value
166162

167163

168164
def test_resolvers_use_their_own_injected_client() -> None:
169-
"""Each resolver derives its KVS client from its own injected client; there is no shared process-global cache."""
165+
"""Each resolver builds its KVS client from its own injected client; there is no shared process-global cache."""
170166
config = Configuration(token='test-token', default_key_value_store_id='default-kvs-id')
171-
client_a = _api_client()
172-
client_b = _api_client()
167+
client_a = MagicMock()
168+
client_b = MagicMock()
173169
resolver_a = AliasResolver(storage_type='Dataset', alias='a', configuration=config, api_client=client_a)
174170
resolver_b = AliasResolver(storage_type='Dataset', alias='b', configuration=config, api_client=client_b)
175171

176-
assert resolver_a._get_default_kvs_client()._http_client is client_a.http_client
177-
assert resolver_b._get_default_kvs_client()._http_client is client_b.http_client
178-
assert client_a.http_client is not client_b.http_client
172+
kvs_a = resolver_a._get_default_kvs_client()
173+
kvs_b = resolver_b._get_default_kvs_client()
174+
175+
# Each resolver routes through its own injected client, and the two yield independent KVS clients.
176+
assert kvs_a is client_a.key_value_store.return_value
177+
assert kvs_b is client_b.key_value_store.return_value
178+
assert kvs_a is not kvs_b
179179

180180

181181
def test_alias_resolution_runs_across_event_loops_with_shared_client() -> None:

0 commit comments

Comments
 (0)