summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ws/tests/shutdown.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/rust/ws/tests/shutdown.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/third_party/rust/ws/tests/shutdown.rs b/third_party/rust/ws/tests/shutdown.rs
new file mode 100644
index 0000000000..1c12345726
--- /dev/null
+++ b/third_party/rust/ws/tests/shutdown.rs
@@ -0,0 +1,41 @@
+extern crate ws;
+
+use std::sync::mpsc::channel;
+use std::thread;
+use std::time::Duration;
+
+#[test]
+fn shutdown_before_connections() {
+ let (tx, rx) = channel();
+ let mut connections = 0;
+
+ let socket = ws::Builder::new()
+ .build(move |_| {
+ tx.send(1).unwrap();
+ |_| Ok(())
+ })
+ .unwrap();
+
+ let handle = socket.broadcaster();
+
+ let t = thread::spawn(move || {
+ socket.listen("127.0.0.1:3012").unwrap();
+ });
+
+ loop {
+ thread::sleep(Duration::from_millis(500));
+ let res = rx.try_recv();
+ assert!(res.is_err());
+ match res {
+ Ok(n) => connections += n,
+ Err(_) => {
+ if connections < 1 {
+ handle.shutdown().unwrap();
+ break;
+ }
+ }
+ }
+ }
+
+ assert!(t.join().is_ok());
+}