Skip to main content

reset_executor_for_test

Function reset_executor_for_test 

Source
pub fn reset_executor_for_test()
Expand description

Completely reset the global executor to a pristine state.

Clears all task slots, queues, deferred ops, flush/scheduler flags, and injected ScheduleFlush/TimeSource. Call at the start of every test to prevent cross-test state leakage.

Note that the signal schedule hook (installed by init_flush_scheduler via std::sync::OnceLock) persists across resets — the hook references the global [EXECUTOR] thread-local, and this function re-initialises that same executor in place rather than replacing it. This is correct behaviour: after reset, signal notifications route to the freshly-cleared global executor.

§Safety / usage

This function is intended only for testing. Calling it while the executor is processing tasks will silently drop all live futures and may cause panics or undefined behavior in running application code.