Skip to content

Commit 95ced97

Browse files
test(shared_runtime): add test
1 parent c9a7043 commit 95ced97

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

  • libdd-shared-runtime/src/shared_runtime

libdd-shared-runtime/src/shared_runtime/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,32 @@ mod tests {
580580
}
581581
assert_eq!(last, -1);
582582
}
583+
584+
#[test]
585+
fn test_after_fork_child_drops_worker_not_restart_on_fork() {
586+
let shared_runtime = SharedRuntime::new().unwrap();
587+
let (worker, receiver) = make_test_worker();
588+
589+
shared_runtime.spawn_worker(worker, false).unwrap();
590+
591+
// Wait for the worker to run at least once
592+
receiver
593+
.recv_timeout(Duration::from_secs(1))
594+
.expect("worker did not run");
595+
596+
shared_runtime.before_fork();
597+
// Drain buffered messages now that the worker is paused
598+
while receiver.try_recv().is_ok() {}
599+
600+
assert!(shared_runtime.after_fork_child().is_ok());
601+
602+
// Worker must be removed from the list
603+
assert_eq!(shared_runtime.workers.lock_or_panic().len(), 0);
604+
605+
// Worker must not produce any more messages (not restarted, not shut down)
606+
assert!(
607+
receiver.recv_timeout(Duration::from_millis(200)).is_err(),
608+
"worker should not run or shut down after fork in child when restart_on_fork is false"
609+
);
610+
}
583611
}

0 commit comments

Comments
 (0)