Skip to content

Commit

Permalink
Execute websocket test assertions
Browse files Browse the repository at this point in the history
The assertions were not doing anthing before, they were only queued to
run
  • Loading branch information
richardpringle committed Oct 18, 2023
1 parent 9ab0bec commit bc2b641
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions crates/net/src/websocket/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,43 +354,38 @@ impl PinnedDrop for WebSocket {
mod tests {
use super::*;
use futures::{SinkExt, StreamExt};
use wasm_bindgen_futures::spawn_local;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn websocket_works() {
async fn websocket_works() {
let ws_echo_server_url =
option_env!("WS_ECHO_SERVER_URL").expect("Did you set WS_ECHO_SERVER_URL?");

let ws = WebSocket::open(ws_echo_server_url).unwrap();
let (mut sender, mut receiver) = ws.split();

spawn_local(async move {
sender
.send(Message::Text(String::from("test 1")))
.await
.unwrap();
sender
.send(Message::Text(String::from("test 2")))
.await
.unwrap();
});

spawn_local(async move {
// ignore first message
// the echo-server uses it to send it's info in the first message
let _ = receiver.next().await;

assert_eq!(
receiver.next().await.unwrap().unwrap(),
Message::Text("test 1".to_string())
);
assert_eq!(
receiver.next().await.unwrap().unwrap(),
Message::Text("test 2".to_string())
);
});
sender
.send(Message::Text(String::from("test 1")))
.await
.unwrap();
sender
.send(Message::Text(String::from("test 2")))
.await
.unwrap();

// ignore first message
// the echo-server uses it to send it's info in the first message
let _ = receiver.next().await;

assert_eq!(
receiver.next().await.unwrap().unwrap(),
Message::Text("test 1".to_string())
);
assert_eq!(
receiver.next().await.unwrap().unwrap(),
Message::Text("test 2".to_string())
);
}
}

0 comments on commit bc2b641

Please sign in to comment.