PrefectHQ
prefect
BlogDocsChangelog

fix: properly drain workers in prefect_test_harness when used in async contexts

#19770
Comparing
devin/1765652244-fix-test-harness-async-cleanup
(
d6c59c8
) with
main
(
af1a9c9
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
0%
465.3 µs464.8 µs
bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s

Ignored

bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-1%
165.7 ms168 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+2%
33.6 ms32.9 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-13%
5.1 ms5.9 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-1%
107 ms107.6 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-54%
6 ms13.2 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s

Commits

Click on a commit to change the comparison range
Base
main
af1a9c9
+0.06%
fix: properly drain workers in prefect_test_harness when used in async contexts Fixes #19762 When prefect_test_harness is used in an async context, the drain_all() and drain() methods return coroutines that were never awaited, causing RuntimeWarning: coroutine 'wait' was never awaited. This fix uses the underlying _drain() method which returns a concurrent.futures.Future that can be waited on synchronously, regardless of whether there's a running event loop. This avoids creating unawaited coroutines in the first place. Changes: - Use _drain() instead of drain()/drain_all() in prefect_test_harness cleanup - Wait synchronously on the futures with concurrent.futures.wait() - Copy EventsWorker instances before iterating to avoid dictionary mutation error - Add regression test that fails if unawaited coroutines are created Co-Authored-By: Nate Nowack <nate@prefect.io>
d6c59c8
10 hours ago
by devin-ai-integration[bot]
© 2025 CodSpeed Technology
Home Terms Privacy Docs