From a1ca230f904cb7158b23fd8fd8969a818d395050 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Sun, 28 Jan 2024 12:54:40 +0100 Subject: [PATCH] Start using serial_test for test serialisation --- Cargo.lock | 72 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + download/Cargo.toml | 1 + download/tests/read-proxy-env.rs | 13 ++---- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86076514269..479e200c42f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -453,6 +453,19 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.14.3", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "deranged" version = "0.3.11" @@ -495,6 +508,7 @@ dependencies = [ "hyper-util", "once_cell", "reqwest", + "serial_test", "tempfile", "thiserror", "tokio", @@ -1153,6 +1167,16 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -1474,6 +1498,29 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2092,6 +2139,31 @@ dependencies = [ "serde", ] +[[package]] +name = "serial_test" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ad9342b3aaca7cb43c45c097dd008d4907070394bd0751a0aa8817e5a018d" +dependencies = [ + "dashmap", + "futures", + "lazy_static", + "log", + "parking_lot", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b93fb4adc70021ac1b47f7d45e8cc4169baaa7ea58483bc5b721d19a26202212" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "sha2" version = "0.10.8" diff --git a/Cargo.toml b/Cargo.toml index 48306b74d5a..8dcd528945a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -169,6 +169,7 @@ opentelemetry-otlp = "0.14.0" opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio"] } proptest = "1.1.0" rustup-macros = { path = "rustup-macros" } +serial_test = "3" tempfile = "3.8" termcolor = "1.2" thiserror = "1.0" diff --git a/download/Cargo.toml b/download/Cargo.toml index 9b1e8b980dc..8328e92b886 100644 --- a/download/Cargo.toml +++ b/download/Cargo.toml @@ -35,4 +35,5 @@ hyper = { version = "1.0", default-features = false, features = [ "server", ] } hyper-util = { version = "0.1.1", features = ["tokio"] } +serial_test.workspace = true tempfile.workspace = true diff --git a/download/tests/read-proxy-env.rs b/download/tests/read-proxy-env.rs index b3ca4727681..fd8c2ac189d 100644 --- a/download/tests/read-proxy-env.rs +++ b/download/tests/read-proxy-env.rs @@ -4,16 +4,14 @@ use std::env::{remove_var, set_var}; use std::error::Error; use std::net::TcpListener; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Mutex; use std::thread; use std::time::Duration; use env_proxy::for_url; use reqwest::{Client, Proxy}; +use serial_test::serial; use url::Url; -static SERIALISE_TESTS: Mutex<()> = Mutex::new(()); - fn scrub_env() { remove_var("http_proxy"); remove_var("https_proxy"); @@ -28,10 +26,8 @@ fn scrub_env() { // Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy #[tokio::test] +#[serial] async fn read_basic_proxy_params() { - let _guard = SERIALISE_TESTS - .lock() - .expect("Unable to lock the test guard"); scrub_env(); set_var("https_proxy", "http://proxy.example.com:8080"); let u = Url::parse("https://www.example.org").ok().unwrap(); @@ -43,12 +39,9 @@ async fn read_basic_proxy_params() { // Tests to verify if socks feature is available and being used #[tokio::test] +#[serial] async fn socks_proxy_request() { static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); - let _guard = SERIALISE_TESTS - .lock() - .expect("Unable to lock the test guard"); - scrub_env(); set_var("all_proxy", "socks5://127.0.0.1:1080");