Skip to content

Commit 2a4a4a9

Browse files
committed
test: Re-raise worker errors via futures in thread-safety test
Use ThreadPoolExecutor and future.result() instead of collecting worker exceptions into a list. A failing worker now re-raises in the main thread (surfacing the actual error directly), and the defensive except branch -- which never ran on a passing build -- is gone, so the test no longer leaves uncovered lines.
1 parent 7b3015e commit 2a4a4a9

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

holoviews/tests/core/test_storeoptions.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,22 @@ def test_concurrent_recustomization_is_thread_safe(self):
188188
# Allocating ids from a recomputed max(store)+1 offset gives concurrent
189189
# calls the same block, so one thread's freshly stored tree is reused
190190
# by another and the id is gone by the time it is propagated, raising
191-
# "New option id ... does not match any option trees".
191+
# "New option id ... does not match any option trees". future.result()
192+
# re-raises any such error from the worker threads, failing the test.
192193
import threading
194+
from concurrent.futures import ThreadPoolExecutor
193195

194-
errors = []
195-
barrier = threading.Barrier(8)
196+
n_workers = 8
197+
barrier = threading.Barrier(n_workers)
196198

197199
def worker(w):
198-
try:
199-
barrier.wait()
200-
for i in range(60):
201-
el = hv.Curve([1, 2, 3], label=f"w{w}")
202-
for _ in range(4):
203-
el = el.opts(linewidth=(i % 5) + 1)
204-
except Exception as exc:
205-
errors.append(exc)
206-
207-
threads = [threading.Thread(target=worker, args=(w,)) for w in range(8)]
208-
for thread in threads:
209-
thread.start()
210-
for thread in threads:
211-
thread.join()
212-
213-
assert not errors, f"concurrent customization raised: {errors[:3]}"
200+
barrier.wait()
201+
for i in range(60):
202+
el = hv.Curve([1, 2, 3], label=f"w{w}")
203+
for _ in range(4):
204+
el = el.opts(linewidth=(i % 5) + 1)
205+
206+
with ThreadPoolExecutor(max_workers=n_workers) as executor:
207+
futures = [executor.submit(worker, w) for w in range(n_workers)]
208+
for future in futures:
209+
future.result()

0 commit comments

Comments
 (0)