Skip to content

Commit 7409372

Browse files
committed
trim latencystore down to just what's needed to dodge zarr-developers/zarr-python#3105 (comment)
1 parent 75abdec commit 7409372

1 file changed

Lines changed: 8 additions & 38 deletions

File tree

‎xarray/tests/test_async.py‎

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import asyncio
2-
import time
3-
from collections.abc import Iterable
4-
from contextlib import asynccontextmanager
52
from typing import Literal, TypeVar
63
from unittest.mock import patch
74

@@ -21,60 +18,33 @@
2118

2219
T_Store = TypeVar("T_Store", bound=Store)
2320

24-
class LatencyStore(WrapperStore[T_Store]):
25-
"""Works the same way as the zarr LoggingStore"""
21+
class ReadOnlyStore(WrapperStore[T_Store]):
22+
"""
23+
We shouldn't need this - but we currently do just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167
2624
27-
latency: float
25+
Works the same way as the zarr LoggingStore.
26+
"""
2827

29-
# TODO only have to add this because of dumb behaviour in zarr where it raises with "ValueError: Store is not read-only but mode is 'r'"
3028
read_only = True
3129

3230
def __init__(
3331
self,
3432
store: T_Store,
35-
latency: float = 0.0,
3633
) -> None:
37-
"""
38-
Store wrapper that adds artificial latency to each get call.
39-
40-
Parameters
41-
----------
42-
store : Store
43-
Store to wrap
44-
latency : float
45-
Amount of artificial latency to add to each get call, in seconds.
46-
"""
4734
super().__init__(store)
48-
self.latency = latency
49-
50-
def __str__(self) -> str:
51-
return f"latency-{self._store}"
52-
53-
def __repr__(self) -> str:
54-
return f"LatencyStore({self._store.__class__.__name__}, '{self._store}', latency={self.latency})"
5535

5636
async def get(
5737
self,
5838
key: str,
5939
prototype: BufferPrototype,
6040
byte_range: ByteRequest | None = None,
6141
) -> Buffer | None:
62-
await asyncio.sleep(self.latency)
6342
return await self._store.get(
6443
key=key, prototype=prototype, byte_range=byte_range
6544
)
6645

67-
async def get_partial_values(
68-
self,
69-
prototype: BufferPrototype,
70-
key_ranges: Iterable[tuple[str, ByteRequest | None]],
71-
) -> list[Buffer | None]:
72-
await asyncio.sleep(self.latency)
73-
return await self._store.get_partial_values(
74-
prototype=prototype, key_ranges=key_ranges
75-
)
7646
else:
77-
LatencyStore = {}
47+
ReadOnlyStore = {}
7848

7949

8050
@pytest.fixture
@@ -106,8 +76,8 @@ def memorystore() -> "MemoryStore":
10676

10777
@pytest.fixture
10878
def store(memorystore) -> "zarr.abc.store.Store":
109-
# TODO we shouldn't need a LatencyStore at all for the patched tests, but we currently use it just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167
110-
return LatencyStore(memorystore, latency=0.0)
79+
# TODO we shouldn't this Store at all for the patched tests, but we currently use it just as a way around https://github.com/zarr-developers/zarr-python/issues/3105#issuecomment-2990367167
80+
return ReadOnlyStore(memorystore)
11181

11282

11383
def get_xr_obj(

0 commit comments

Comments
 (0)