From 8baeced2f3c3a9a6ca1d66472b3195830ca6e2d2 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Tue, 13 Feb 2024 15:06:37 +0200 Subject: [PATCH] Change tests to not require multi threaded runtime --- changelog.d/+refactor-tests.internal.md | 1 + tests/Cargo.toml | 2 +- tests/issue1317/Cargo.toml | 2 +- tests/rust-bypassed-unix-socket/Cargo.toml | 2 +- tests/rust-unix-socket-client/Cargo.toml | 2 +- tests/src/traffic.rs | 44 +++++++++++----------- tests/src/traffic/steal.rs | 32 ++++++++-------- 7 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 changelog.d/+refactor-tests.internal.md diff --git a/changelog.d/+refactor-tests.internal.md b/changelog.d/+refactor-tests.internal.md new file mode 100644 index 00000000000..f73fb4c31b2 --- /dev/null +++ b/changelog.d/+refactor-tests.internal.md @@ -0,0 +1 @@ +Change tests to not require multi threaded runtime \ No newline at end of file diff --git a/tests/Cargo.toml b/tests/Cargo.toml index b8b63b9b653..4fd69280853 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -11,7 +11,7 @@ k8s-openapi.workspace = true kube.workspace = true reqwest.workspace = true regex.workspace = true -tokio = { workspace = true, features = ["rt", "rt-multi-thread", "net", "macros", "process"] } +tokio = { workspace = true, features = ["rt", "net", "macros", "process"] } serde_json.workspace = true mirrord = { artifact = "bin", path = "../mirrord/cli" } mirrord-operator = { path = "../mirrord/operator" } diff --git a/tests/issue1317/Cargo.toml b/tests/issue1317/Cargo.toml index 6ee7e4ad6ab..0b5646841f0 100644 --- a/tests/issue1317/Cargo.toml +++ b/tests/issue1317/Cargo.toml @@ -16,7 +16,7 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "macros", "process"] } +tokio = { version = "1", features = ["rt", "net", "macros", "process"] } hyper = { git = "https://github.com/meowjesty/hyper", branch = "master", features = ["full"] } tracing = { git = "https://github.com/metalbear-co/tracing", package = "tracing", branch = "worker_options_non_blocking_v1" } actix-web = "4" diff --git a/tests/rust-bypassed-unix-socket/Cargo.toml b/tests/rust-bypassed-unix-socket/Cargo.toml index 6ebd2ce9280..fe4ddc81615 100644 --- a/tests/rust-bypassed-unix-socket/Cargo.toml +++ b/tests/rust-bypassed-unix-socket/Cargo.toml @@ -16,4 +16,4 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio = { version = "1.26", features = ["rt", "rt-multi-thread", "macros", "net", "io-util"] } +tokio = { version = "1.26", features = ["rt", "macros", "net", "io-util"] } diff --git a/tests/rust-unix-socket-client/Cargo.toml b/tests/rust-unix-socket-client/Cargo.toml index 9971f98b991..f6b8ddd8fc1 100644 --- a/tests/rust-unix-socket-client/Cargo.toml +++ b/tests/rust-unix-socket-client/Cargo.toml @@ -16,4 +16,4 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio = { version = "1.26", features = ["rt", "rt-multi-thread", "macros", "net", "io-util"] } +tokio = { version = "1.26", features = ["rt", "macros", "net", "io-util"] } diff --git a/tests/src/traffic.rs b/tests/src/traffic.rs index f4b8fccbe13..7ba92033669 100644 --- a/tests/src/traffic.rs +++ b/tests/src/traffic.rs @@ -18,7 +18,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] pub async fn remote_dns_enabled_works(#[future] service: KubeService) { let service = service.await; @@ -35,7 +35,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] pub async fn remote_dns_lookup_google(#[future] service: KubeService) { let service = service.await; @@ -55,7 +55,7 @@ mod traffic { // directly sent out from the local application). #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn outgoing_traffic_single_request_enabled(#[future] service: KubeService) { let service = service.await; let node_command = vec![ @@ -71,7 +71,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[should_panic] pub async fn outgoing_traffic_single_request_ipv6(#[future] service: KubeService) { let service = service.await; @@ -88,7 +88,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn outgoing_traffic_single_request_disabled(#[future] service: KubeService) { let service = service.await; let node_command = vec![ @@ -111,7 +111,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn outgoing_traffic_make_request_after_listen(#[future] service: KubeService) { let service = service.await; let node_command = vec![ @@ -126,7 +126,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn outgoing_traffic_make_request_localhost(#[future] service: KubeService) { let service = service.await; let node_command = vec![ @@ -144,7 +144,7 @@ mod traffic { /// that and verifies that mirrord intercepts and forwards the outgoing udp message. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] pub async fn outgoing_traffic_udp_with_connect( #[future] udp_logger_service: KubeService, @@ -229,7 +229,7 @@ mod traffic { /// filter to resolve the remote host names. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] pub async fn outgoing_traffic_filter_udp_with_connect( config_dir: &std::path::PathBuf, @@ -347,7 +347,7 @@ mod traffic { /// application calls `connect` on a UDP socket with outgoing traffic disabled on mirrord. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(30))] pub async fn outgoing_disabled_udp(#[future] service: KubeService) { let service = service.await; @@ -390,7 +390,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn go19_outgoing_traffic_single_request_enabled(#[future] service: KubeService) { let command = vec!["go-e2e-outgoing/19.go_test_app"]; test_go(service, command).await; @@ -398,7 +398,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] pub async fn go20_outgoing_traffic_single_request_enabled(#[future] service: KubeService) { let command = vec!["go-e2e-outgoing/20.go_test_app"]; @@ -407,7 +407,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn go21_outgoing_traffic_single_request_enabled(#[future] service: KubeService) { let command = vec!["go-e2e-outgoing/21.go_test_app"]; test_go(service, command).await; @@ -415,7 +415,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] pub async fn go19_dns_lookup(#[future] service: KubeService) { let command = vec!["go-e2e-dns/19.go_test_app"]; @@ -424,7 +424,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] pub async fn go20_dns_lookup(#[future] service: KubeService) { let command = vec!["go-e2e-dns/20.go_test_app"]; @@ -433,7 +433,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] pub async fn go21_dns_lookup(#[future] service: KubeService) { let command = vec!["go-e2e-dns/21.go_test_app"]; @@ -442,7 +442,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] pub async fn listen_localhost(#[future] service: KubeService) { let service = service.await; let node_command = vec!["node", "node-e2e/listen/test_listen_localhost.mjs"]; @@ -454,7 +454,7 @@ mod traffic { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] pub async fn gethostname_remote_result(#[future] hostname_service: KubeService) { let service = hostname_service.await; @@ -475,7 +475,7 @@ mod traffic { /// 3. Verify the client app did not panic. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] pub async fn outgoing_unix_stream_pathname( #[future] @@ -512,7 +512,7 @@ mod traffic { /// case of connections to unix sockets). #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] pub async fn outgoing_bypassed_unix_stream_pathname(#[future] service: KubeService) { let service = service.await; @@ -531,7 +531,7 @@ mod traffic { } #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[cfg_attr(not(any(feature = "ephemeral", feature = "job")), ignore)] pub async fn test_outgoing_traffic_many_requests_enabled(#[future] service: KubeService) { let service = service.await; @@ -548,7 +548,7 @@ mod traffic { } #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[cfg_attr(not(any(feature = "ephemeral", feature = "job")), ignore)] pub async fn test_outgoing_traffic_many_requests_disabled(#[future] service: KubeService) { let service = service.await; diff --git a/tests/src/traffic/steal.rs b/tests/src/traffic/steal.rs index 17809f0babe..ccfa44329ef 100644 --- a/tests/src/traffic/steal.rs +++ b/tests/src/traffic/steal.rs @@ -2,15 +2,15 @@ #[cfg(test)] mod steal { use std::{ - io::{BufRead, BufReader, Read, Write}, - net::{SocketAddr, TcpStream}, + io::{BufRead, Read, Write}, + net::SocketAddr, time::Duration, }; use kube::Client; use reqwest::{header::HeaderMap, Url}; use rstest::*; - use tokio::time::sleep; + use tokio::{io::BufReader, net::TcpStream, time::sleep}; use tokio_tungstenite::connect_async; use crate::utils::{ @@ -22,7 +22,7 @@ mod steal { #[cfg_attr(not(any(feature = "ephemeral", feature = "job")), ignore)] #[cfg(target_os = "linux")] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] async fn steal_http_traffic( #[future] service: KubeService, @@ -61,7 +61,7 @@ mod steal { #[cfg_attr(not(any(feature = "ephemeral", feature = "job")), ignore)] #[cfg(target_os = "linux")] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] async fn steal_http_traffic_with_flush_connections( #[future] service: KubeService, @@ -106,7 +106,7 @@ mod steal { /// closes a socket. #[cfg_attr(not(any(feature = "ephemeral", feature = "job")), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] async fn close_socket(#[future] service: KubeService, #[future] kube_client: Client) { let application = Application::PythonCloseSocket; @@ -185,7 +185,7 @@ mod steal { /// application closes a socket, we stop stealing existing connections. #[ignore] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(240))] async fn close_socket_keep_connection( #[future] service: KubeService, @@ -264,7 +264,7 @@ mod steal { /// then run test with MIRRORD_TESTS_USE_BINARY=../target/universal-apple-darwin/debug/mirrord #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn filter_with_single_client_and_only_matching_requests( #[future] service: KubeService, @@ -307,7 +307,7 @@ mod steal { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn filter_with_single_client_and_only_matching_requests_new( config_dir: &std::path::PathBuf, @@ -348,7 +348,7 @@ mod steal { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn filter_with_single_client_requests_by_path( config_dir: &std::path::PathBuf, @@ -404,7 +404,7 @@ mod steal { #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn test_filter_with_single_client_and_only_matching_requests_http2( #[future] http2_service: KubeService, @@ -469,7 +469,7 @@ mod steal { /// then run test with MIRRORD_TESTS_USE_BINARY=../target/universal-apple-darwin/debug/mirrord #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn filter_with_single_client_and_some_matching_requests( #[future] service: KubeService, @@ -538,7 +538,7 @@ mod steal { /// app does not see the traffic. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(120))] async fn complete_passthrough( #[future] tcp_echo_service: KubeService, @@ -566,11 +566,11 @@ mod steal { .await; let addr = SocketAddr::new(host.trim().parse().unwrap(), port as u16); - let mut stream = TcpStream::connect(addr).unwrap(); + let mut stream = TcpStream::connect(addr).await.unwrap(); stream.write(tcp_data.as_bytes()).unwrap(); let mut reader = BufReader::new(stream); let mut buf = String::new(); - reader.read_line(&mut buf).unwrap(); + reader.read_line(&mut buf).await.unwrap(); println!("Got response: {buf}"); // replace "remote: " with empty string, since the response can be split into frames // and we just need assert the final response @@ -603,7 +603,7 @@ mod steal { /// app does not see the traffic. #[cfg_attr(not(feature = "job"), ignore)] #[rstest] - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + #[tokio::test] #[timeout(Duration::from_secs(60))] async fn websocket_upgrade( #[future] websocket_service: KubeService,