()
| 2353 | |
| 2354 | |
| 2355 | def test_store_locks(): |
| 2356 | d = da.ones((10, 10), chunks=(2, 2)) |
| 2357 | a, b = d + 1, d + 2 |
| 2358 | |
| 2359 | at = np.zeros(shape=(10, 10)) |
| 2360 | bt = np.zeros(shape=(10, 10)) |
| 2361 | |
| 2362 | lock = CounterLock() |
| 2363 | # Ensure same lock applies over multiple stores |
| 2364 | at = NonthreadSafeStore() |
| 2365 | v = store([a, b], [at, at], lock=lock, scheduler="threads", num_workers=10) |
| 2366 | assert lock.acquire_count == lock.release_count == a.npartitions + b.npartitions |
| 2367 | assert v is None |
| 2368 | |
| 2369 | # Don't assume thread safety by default |
| 2370 | at = NonthreadSafeStore() |
| 2371 | assert store(a, at, scheduler="threads", num_workers=10) is None |
| 2372 | assert a.store(at, scheduler="threads", num_workers=10) is None |
| 2373 | |
| 2374 | # Ensure locks can be removed |
| 2375 | at = ThreadSafeStore() |
| 2376 | for i in range(10): |
| 2377 | st = a.store(at, lock=False, scheduler="threads", num_workers=10) |
| 2378 | assert st is None |
| 2379 | if at.max_concurrent_uses > 1: |
| 2380 | break |
| 2381 | if i == 9: |
| 2382 | assert False |
| 2383 | |
| 2384 | # Verify number of lock calls |
| 2385 | nchunks = sum(math.prod(map(len, e.chunks)) for e in (a, b)) |
| 2386 | for c in (False, True): |
| 2387 | at = np.zeros(shape=(10, 10)) |
| 2388 | bt = np.zeros(shape=(10, 10)) |
| 2389 | lock = CounterLock() |
| 2390 | |
| 2391 | v = store([a, b], [at, bt], lock=lock, compute=c, return_stored=True) |
| 2392 | assert all(isinstance(e, Array) for e in v) |
| 2393 | |
| 2394 | da.compute(v) |
| 2395 | |
| 2396 | # When `return_stored=True` and `compute=False`, |
| 2397 | # the lock should be acquired only once for store and load steps |
| 2398 | # as they are fused together into one step. |
| 2399 | assert lock.acquire_count == lock.release_count |
| 2400 | if c: |
| 2401 | assert lock.acquire_count == 2 * nchunks |
| 2402 | else: |
| 2403 | assert lock.acquire_count == nchunks |
| 2404 | |
| 2405 | |
| 2406 | def test_store_method_return(): |
nothing calls this directly
no test coverage detected