-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix receive_impl ignoring options.delay_blocking
- Loading branch information
Showing
5 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "stress_test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tokio = "1" | ||
tungstenite = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#![allow(clippy::unwrap_used, clippy::disallowed_methods)] // We are just testing here. | ||
|
||
use std::net::TcpListener; | ||
use std::net::TcpStream; | ||
use std::time::Instant; | ||
|
||
use tungstenite::Message; | ||
|
||
fn main() { | ||
let args = std::env::args().skip(1).collect::<Vec<_>>(); | ||
let [kind, action, address] = &args[..] else { | ||
eprintln!("Usage: stress_test <tcp|ws> <send|recv> <address>"); | ||
return; | ||
}; | ||
match (kind.as_str(), action.as_str()) { | ||
("tcp", "send") => send_tcp(address), | ||
("tcp", "recv") => recv_tcp(address), | ||
("ws", "send") => send_ws(address), | ||
("ws", "recv") => recv_ws(address), | ||
_ => { | ||
eprintln!("Usage: stress_test <tcp|ws> <send|recv> <address>"); | ||
} | ||
} | ||
} | ||
|
||
fn send_tcp(address: &str) { | ||
use std::io::Write as _; | ||
|
||
println!("Connecting to: {address}"); | ||
let mut stream = TcpStream::connect(address).unwrap(); | ||
|
||
println!("Sending 1M messages"); | ||
let start = Instant::now(); | ||
for i in 0..1_000_000 { | ||
stream.write_all(&vec![i as u8; 4 * 1024]).unwrap(); | ||
} | ||
let duration = start.elapsed(); | ||
println!("Sent all messages in {}ms", duration.as_millis()); | ||
} | ||
|
||
fn recv_tcp(address: &str) { | ||
use std::io::Read as _; | ||
|
||
let server = TcpListener::bind(address).unwrap(); | ||
println!("Listening on: {address}"); | ||
println!("Waiting for client"); | ||
let (mut client, _) = server.accept().unwrap(); | ||
let mut buf = vec![0; 4 * 1024]; | ||
println!("Client connected"); | ||
let start = Instant::now(); | ||
for i in 0..1_000_000 { | ||
client.read_exact(&mut buf).unwrap(); | ||
assert_eq!(buf[0], i as u8, "Invalid message"); | ||
} | ||
let duration = start.elapsed(); | ||
println!("Received all messages in {}ms", duration.as_millis()); | ||
} | ||
|
||
fn send_ws(address: &str) { | ||
println!("Connecting to: ws://{address}"); | ||
let stream = TcpStream::connect(address).unwrap(); | ||
let (mut stream, _) = tungstenite::client(format!("ws://{address}"), stream).unwrap(); | ||
println!("{:?}", stream.get_config()); | ||
|
||
println!("Sending 1M messages"); | ||
let start = Instant::now(); | ||
for i in 0..1_000_000 { | ||
stream | ||
.send(Message::Binary(vec![i as u8; 4 * 1024])) | ||
.unwrap(); | ||
} | ||
let duration = start.elapsed(); | ||
println!("Sent all messages in {}ms", duration.as_millis()); | ||
} | ||
|
||
fn recv_ws(address: &str) { | ||
let server = TcpListener::bind(address).unwrap(); | ||
println!("Listening on: ws://{address}"); | ||
println!("Waiting for client"); | ||
let (client, _) = server.accept().unwrap(); | ||
let mut client = tungstenite::accept(client).unwrap(); | ||
println!("{:?}", client.get_config()); | ||
println!("Client connected"); | ||
let start = Instant::now(); | ||
for _ in 0..1_000_000 { | ||
let message = client.read().unwrap(); | ||
assert!( | ||
matches!(message, Message::Binary(_)), | ||
"unexpected message: {message:?}" | ||
); | ||
} | ||
let duration = start.elapsed(); | ||
println!("Received all messages in {}ms", duration.as_millis()); | ||
} |