Make the tests that failed to acquire locks panic explicitly
SteveLauC opened this issue · 4 comments
We have some process-wide Mutex locks in test.rs
to ensure tests that need to modify global states will be executed sequentially:
Lines 59 to 74 in a7db481
This should work well if the corresponding test succeeds, but once a test holding the lock failed, the thread running that test panicked, the lock got poisoned, then other tests (threads) cannot acquire the lock, and since we don't check if the lock acquisition is successful in our tests, under such scenario, those global locks won't work at all.
Line 43 in a7db481
Given that those global locks do not work under the above case, we can get some unexpected results from our test, e.g., see these 2 failures here, they want to wait for the child process created by themselves, but got the children of others:
---- test_pty::test_forkpty stdout ----
thread 'test_pty::test_forkpty' panicked at 'assertion failed: `(left == right)`
left: `Signaled(Pid(4405), SIGTERM, false)`,
right: `Signaled(Pid(4628), SIGTERM, false)`', test/test_pty.rs:273:13
---- test_unistd::test_wait stdout ----
thread 'test_unistd::test_wait' panicked at 'assertion failed: `(left == right)`
left: `Ok(Signaled(Pid(4628), SIGTERM, false))`,
right: `Ok(Exited(Pid(4733), 0))`', test/test_unistd.rs:112:13
In my mind, I am thinking about calling .unwrap()
on lock()
so that the tests that cannot acquire the lock will panic explicitly, which would make things clearer, though I cannot say it is generally a better approach. cc @asomers
Well, I just realized that we are using std::sync::Mutex
ONLY for FORK_MTX
, so the problem described in this issue only applies to it.
Ok, I will change it back tomorrow