Skip to content

Commit babdd72

Browse files
committed
tests: compare disposal thread objects after manager shutdown
Manager shutdown can retire a pool owner before the executor creates its worker. PyPy can reuse that owner's native thread ID, so comparing saved integer IDs falsely reports owner-thread disposal. Retain actual Thread objects and verify worker execution context. Preserve the exactly-once disposal and released-credit assertions; an exactly-once owner-disposal negative control still fails the owner-exclusion assertion.
1 parent 4747f2b commit babdd72

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎tests/unit/test_management_runtime.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import deque
22
from concurrent.futures import (
33
Future, ThreadPoolExecutor, as_completed, wait, TimeoutError)
4-
from threading import Barrier, Event, Lock, Thread, get_ident
4+
from threading import Barrier, Event, Lock, Thread, current_thread, get_ident
55

66
import pytest
77

@@ -502,6 +502,10 @@ def test_completed_executor_future_does_not_dispose_on_registering_owner(
502502
manager, dispatch = runtime
503503
resource = object()
504504
disposal_threads = []
505+
disposal_contexts = []
506+
def dispose(value):
507+
disposal_threads.append(current_thread())
508+
disposal_contexts.append(execution_context())
505509
with ThreadPoolExecutor(1) as executor:
506510
class ClosingExecutor:
507511
def submit(self, function):
@@ -514,13 +518,15 @@ def submit(self, function):
514518
return physical
515519
future = manager.submit(lambda record: manager.work(
516520
record, ClosingExecutor(), lambda: resource,
517-
dispose=lambda value: disposal_threads.append(get_ident())))
521+
dispose=dispose))
518522
with pytest.raises(ManagementClosed):
519523
future.result(5)
520524
manager.join(5)
521525
assert len(disposal_threads) == 1
522-
assert disposal_threads[0] not in {
523-
thread.ident for thread in manager._threads}
526+
# Native thread IDs may be reused after close retires an owner. Keep the
527+
# actual Thread objects to distinguish that owner from a later worker.
528+
assert all(disposal_threads[0] is not thread for thread in manager._threads)
529+
assert disposal_contexts == ['worker']
524530
assert manager.counts()['ordinary'] == 0
525531

526532

0 commit comments

Comments
 (0)