containers / youki

A container runtime written in Rust
https://containers.github.io/youki/
Apache License 2.0
6.2k stars 337 forks source link

Reset console sockets to original in setup_console test #2764

Closed YJDoc2 closed 5 months ago

YJDoc2 commented 5 months ago

See #150 for detailed reasoning, but in short - right now, when a test fails the usual stack test and reason of assertion failure that is given by rust testing is not displayed. Reason for this is in test_setup_console , we change our std to a different socket, which is then carried on. My guess is that when a test fails, the test binary is supposed to print error stack etc to its std. But because we change the std* fds, the test harness cannot capture them, and thus it does not get logged correctly. I'm not sure why all the o/p after the setup_console test is run is not lost this way.

In this PR, we store the proper std* fds, and restore them before our final assertion, so that the rest o/p is not lost.

For validation, add a dummy test like

#[test]
fn fake_test(){
    let t:Option<usize> = None;
    t.unwrap();
}

And run just test-basic in main branch. The o/p will show that the test failed, but the stack won't be there. Do the same with this branch, and the o/p is present.

Fixes #150