From e439ba53477dbd7a0ec40531772dcab23e161060 Mon Sep 17 00:00:00 2001 From: jprochazk Date: Thu, 24 Oct 2024 13:26:43 +0200 Subject: [PATCH] remove temp code --- Cargo.lock | 8 ---- Cargo.toml | 2 +- example_app/src/lib.rs | 2 + stress_test/Cargo.toml | 13 ------ stress_test/src/main.rs | 94 ----------------------------------------- 5 files changed, 3 insertions(+), 116 deletions(-) delete mode 100644 stress_test/Cargo.toml delete mode 100644 stress_test/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index ece72e3..a6db756 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2735,14 +2735,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stress_test" -version = "0.1.0" -dependencies = [ - "tokio", - "tungstenite", -] - [[package]] name = "strict-num" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 17bdba6..2dde38a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["ewebsock", "example_app", "echo_server", "stress_test"] +members = ["ewebsock", "example_app", "echo_server"] [patch.crates-io] # If you want to use the bleeding edge version of egui/eframe: diff --git a/example_app/src/lib.rs b/example_app/src/lib.rs index 38e3d8a..19f4211 100644 --- a/example_app/src/lib.rs +++ b/example_app/src/lib.rs @@ -1,3 +1,5 @@ +//! Example application. + mod app; pub use app::ExampleApp; diff --git a/stress_test/Cargo.toml b/stress_test/Cargo.toml deleted file mode 100644 index 45f21cb..0000000 --- a/stress_test/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[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 diff --git a/stress_test/src/main.rs b/stress_test/src/main.rs deleted file mode 100644 index 4b3c605..0000000 --- a/stress_test/src/main.rs +++ /dev/null @@ -1,94 +0,0 @@ -#![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::>(); - let [kind, action, address] = &args[..] else { - eprintln!("Usage: stress_test
"); - 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
"); - } - } -} - -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()); -}