Fix nondeterministic failures in poll_oneoff_stdio.

Adjust this test so that it tolerates poll_oneoff returning that both a
timeout occurred and an input is ready for reading, at the same time.
This commit is contained in:
Dan Gohman
2021-03-15 10:48:02 -07:00
parent a46daa7eee
commit 2d3f2adf04

View File

@@ -46,22 +46,23 @@ unsafe fn test_stdin_read() {
let out = poll_oneoff_impl(&r#in).unwrap(); let out = poll_oneoff_impl(&r#in).unwrap();
// The result should be either a timeout, or that stdin is ready for reading. // The result should be either a timeout, or that stdin is ready for reading.
// Both are valid behaviors that depend on the test environment. // Both are valid behaviors that depend on the test environment.
assert_eq!(out.len(), 1, "should return 1 event"); assert!(out.len() >= 1, "should return at least 1 event");
let event = &out[0]; for event in out {
if event.r#type == wasi::EVENTTYPE_CLOCK { if event.r#type == wasi::EVENTTYPE_CLOCK {
assert_errno!(event.error, wasi::ERRNO_SUCCESS); assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!( assert_eq!(
event.userdata, CLOCK_ID, event.userdata, CLOCK_ID,
"the event.userdata should contain CLOCK_ID", "the event.userdata should contain CLOCK_ID",
); );
} else if event.r#type == wasi::EVENTTYPE_FD_READ { } else if event.r#type == wasi::EVENTTYPE_FD_READ {
assert_errno!(event.error, wasi::ERRNO_SUCCESS); assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!( assert_eq!(
event.userdata, STDIN_ID, event.userdata, STDIN_ID,
"the event.userdata should contain STDIN_ID", "the event.userdata should contain STDIN_ID",
); );
} else { } else {
panic!("unexpected event type {}", event.r#type); panic!("unexpected event type {}", event.r#type);
}
} }
} }