Created
November 4, 2020 05:10
-
-
Save keepsimple1/f5b758b139c87a4695c969ab2de52369 to your computer and use it in GitHub Desktop.
A test case for quiche - send_after_shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/lib.rs b/src/lib.rs | |
index 79c942b..227f07f 100644 | |
--- a/src/lib.rs | |
+++ b/src/lib.rs | |
@@ -7746,6 +7746,65 @@ mod tests { | |
let result2 = pipe.server.dgram_recv(&mut buf); | |
assert_eq!(result2, Err(Error::Done)); | |
} | |
+ | |
+ #[test] | |
+ fn send_after_shutdown() { | |
+ let mut buf = [0; 65535]; | |
+ let mut pipe = testing::Pipe::default().unwrap(); | |
+ assert_eq!(pipe.handshake(&mut buf), Ok(())); | |
+ | |
+ // Client sends some request | |
+ assert_eq!(pipe.client.stream_send(4, b"aaaaa", false), Ok(5)); | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ | |
+ // Server sends some response | |
+ assert_eq!( | |
+ pipe.server.stream_send(4, b"aaaaabbbbbaaaaa", false), | |
+ Ok(15) | |
+ ); | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ | |
+ // Client stream is readable | |
+ let mut readable = pipe.client.readable(); | |
+ assert_eq!(readable.next(), Some(4)); | |
+ | |
+ // Client drains stream. | |
+ let mut b = [0; 15]; | |
+ pipe.client.stream_recv(4, &mut b).unwrap(); | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ | |
+ // Server is writable | |
+ let mut writable = pipe.server.writable(); | |
+ assert_eq!(writable.next(), Some(4)); | |
+ | |
+ // Start a new stream (8) | |
+ assert_eq!(pipe.client.stream_send(8, b"bbbbb", false), Ok(5)); | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ | |
+ // Server shuts down Write on stream 4 | |
+ let error_code: u64 = 12345; | |
+ pipe.server | |
+ .stream_shutdown(4, Shutdown::Write, error_code) | |
+ .unwrap(); | |
+ | |
+ // Try to write stream 4 on server (Comment out this block to pass the test) | |
+ let mut count = 0; | |
+ while let Ok(sz) = pipe.server.stream_send(4, b"ccccc", false) { | |
+ println!("try {} on stream 4 (already shutdown)", count); | |
+ if sz == 0 { | |
+ break; | |
+ } | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ count += 1; | |
+ } | |
+ | |
+ // Try to send some response on stream 8 | |
+ assert_eq!( | |
+ pipe.server.stream_send(8, b"dddddeeeee", false), | |
+ Ok(10) | |
+ ); | |
+ assert_eq!(pipe.advance(&mut buf), Ok(())); | |
+ } | |
} | |
pub use crate::packet::Header; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment