From 32c4efb86e23be315ad8128068d519a76ac496e2 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 25 Sep 2017 01:08:20 -0700 Subject: [PATCH] test(server): fix flaky pipeline disabled test --- tests/server.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/server.rs b/tests/server.rs index bf9dc406..b804cece 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -438,7 +438,7 @@ fn expect_continue() { } #[test] -fn pipline_disabled() { +fn pipeline_disabled() { let server = serve(); let mut req = connect(server.addr()); server.reply().status(hyper::Ok); @@ -456,8 +456,23 @@ fn pipline_disabled() { let mut buf = vec![0; 4096]; let n = req.read(&mut buf).expect("read 1"); assert_ne!(n, 0); - let n = req.read(&mut buf).expect("read 2"); - assert_ne!(n, 0); + // Woah there. What? + // + // This test is wishy-washy because of race conditions in access of the + // socket. The test is still useful, since it allows for the responses + // to be received in 2 reads. But it might sometimes come in 1 read. + // + // TODO: add in a delay to the `ServeReply` interface, to allow this + // delay to prevent the 2 writes from happening before this test thread + // can read from the socket. + match req.read(&mut buf) { + Ok(n) => { + // won't be 0, because we didn't say to close, and so socket + // will be open until `server` drops + assert_ne!(n, 0); + } + Err(_) => (), + } } #[test] @@ -579,8 +594,6 @@ impl NewService for TestService { fn new_service(&self) -> std::io::Result { Ok(self.clone()) } - - } impl Service for TestService {