@@ -120,7 +120,6 @@ async def measure(self):
120
120
@requires_zarr_v3
121
121
@pytest .mark .asyncio
122
122
class TestAsyncLoad :
123
- N_LOADS : int = 5
124
123
LATENCY : float = 1.0
125
124
126
125
@pytest .fixture (params = ["ds" , "da" , "var" ])
@@ -136,21 +135,42 @@ def xr_obj(self, request, memorystore) -> xr.Dataset | xr.DataArray | xr.Variabl
136
135
case "ds" :
137
136
return ds
138
137
139
- def assert_time_as_expected (self , total_time : float ) -> None :
140
- assert total_time > self .LATENCY # Cannot possibly be quicker than this
138
+ def assert_time_as_expected (
139
+ self , total_time : float , latency : float , n_loads : int
140
+ ) -> None :
141
+ assert total_time > latency # Cannot possibly be quicker than this
141
142
assert (
142
- total_time < self . LATENCY * self . N_LOADS
143
+ total_time < latency * n_loads
143
144
) # If this isn't true we're gaining nothing from async
144
145
assert (
145
- abs (total_time - self .LATENCY ) < 2.0
146
- ) # Should take approximately LATENCY seconds, but allow some buffer
146
+ abs (total_time - latency ) < 2.0
147
+ ) # Should take approximately `latency` seconds, but allow some buffer
148
+
149
+ async def test_concurrent_load_multiple_objects (self , xr_obj ) -> None :
150
+ N_OBJECTS = 5
147
151
148
- async def test_async_load (self , xr_obj ):
149
152
async with AsyncTimer ().measure () as timer :
150
- tasks = [xr_obj .load_async () for _ in range (self . N_LOADS )]
153
+ tasks = [xr_obj .load_async () for _ in range (N_OBJECTS )]
151
154
results = await asyncio .gather (* tasks )
152
155
153
156
for result in results :
154
157
xrt .assert_identical (result , xr_obj .load ())
155
158
156
- self .assert_time_as_expected (timer .total_time )
159
+ self .assert_time_as_expected (
160
+ total_time = timer .total_time , latency = self .LATENCY , n_loads = N_OBJECTS
161
+ )
162
+
163
+ async def test_concurrent_load_multiple_variables (self , memorystore ) -> None :
164
+ latencystore = LatencyStore (memorystore , latency = self .LATENCY )
165
+ ds = xr .open_zarr (latencystore , zarr_format = 3 , consolidated = False , chunks = None )
166
+
167
+ # TODO up the number of variables in the dataset?
168
+ async with AsyncTimer ().measure () as timer :
169
+ result_ds = await ds .load_async ()
170
+
171
+ xrt .assert_identical (result_ds , ds .load ())
172
+
173
+ # 2 because there are 2 lazy variables in the dataset
174
+ self .assert_time_as_expected (
175
+ total_time = timer .total_time , latency = self .LATENCY , n_loads = 2
176
+ )
0 commit comments