@@ -101,27 +101,70 @@ def memorystore() -> "MemoryStore":
101
101
@requires_zarr_v3
102
102
@pytest .mark .asyncio
103
103
class TestAsyncLoad :
104
- async def test_async_load_variable (self , memorystore ):
105
- N_LOADS = 5
106
- LATENCY = 1.0
104
+ N_LOADS = 10
105
+ LATENCY = 1.0
107
106
108
- latencystore = LatencyStore (memorystore , latency = LATENCY )
107
+ # TODO refactor these tests
108
+ async def test_async_load_variable (self , memorystore ):
109
+ latencystore = LatencyStore (memorystore , latency = self .LATENCY )
109
110
ds = xr .open_zarr (latencystore , zarr_format = 3 , consolidated = False , chunks = None )
110
111
111
112
# TODO add async load to Dataset and DataArray as well as to Variable
112
113
# TODO change the syntax to `.async.load()`?
113
114
start_time = time .time ()
114
- tasks = [ds ["foo" ].variable .async_load () for _ in range (N_LOADS )]
115
+ tasks = [ds ["foo" ].variable .async_load () for _ in range (self . N_LOADS )]
115
116
results = await asyncio .gather (* tasks )
116
117
total_time = time .time () - start_time
117
118
118
119
for result in results :
119
120
xrt .assert_identical (result , ds ["foo" ].variable .load ())
120
121
121
- assert total_time > LATENCY # Cannot possibly be quicker than this
122
+ assert total_time > self .LATENCY # Cannot possibly be quicker than this
123
+ assert (
124
+ total_time < self .LATENCY * self .N_LOADS
125
+ ) # If this isn't true we're gaining nothing from async
126
+ assert (
127
+ abs (total_time - self .LATENCY ) < 0.5
128
+ ) # Should take approximately LATENCY seconds, but allow some buffer
129
+
130
+ async def test_async_load_dataarray (self , memorystore ):
131
+ latencystore = LatencyStore (memorystore , latency = self .LATENCY )
132
+ ds = xr .open_zarr (latencystore , zarr_format = 3 , consolidated = False , chunks = None )
133
+
134
+ # TODO change the syntax to `.async.load()`?
135
+ start_time = time .time ()
136
+ tasks = [ds ["foo" ].async_load () for _ in range (self .N_LOADS )]
137
+ results = await asyncio .gather (* tasks )
138
+ total_time = time .time () - start_time
139
+
140
+ for result in results :
141
+ xrt .assert_identical (result , ds ["foo" ].load ())
142
+
143
+ assert total_time > self .LATENCY # Cannot possibly be quicker than this
144
+ assert (
145
+ total_time < self .LATENCY * self .N_LOADS
146
+ ) # If this isn't true we're gaining nothing from async
147
+ assert (
148
+ abs (total_time - self .LATENCY ) < 0.5
149
+ ) # Should take approximately LATENCY seconds, but allow some buffer
150
+
151
+ async def test_async_load_dataset (self , memorystore ):
152
+ latencystore = LatencyStore (memorystore , latency = self .LATENCY )
153
+ ds = xr .open_zarr (latencystore , zarr_format = 3 , consolidated = False , chunks = None )
154
+
155
+ # TODO change the syntax to `.async.load()`?
156
+ start_time = time .time ()
157
+ tasks = [ds .async_load () for _ in range (self .N_LOADS )]
158
+ results = await asyncio .gather (* tasks )
159
+ total_time = time .time () - start_time
160
+
161
+ for result in results :
162
+ xrt .assert_identical (result , ds .load ())
163
+
164
+ assert total_time > self .LATENCY # Cannot possibly be quicker than this
122
165
assert (
123
- total_time < LATENCY * N_LOADS
166
+ total_time < self . LATENCY * self . N_LOADS
124
167
) # If this isn't true we're gaining nothing from async
125
168
assert (
126
- abs (total_time - LATENCY ) < 0.5
169
+ abs (total_time - self . LATENCY ) < 0.5
127
170
) # Should take approximately LATENCY seconds, but allow some buffer
0 commit comments