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