Simplify test environment setup to return TempDir directly
- Remove TestEnvironment struct and return TempDir from setup function - Update tests to compute paths from temp_dir.path() on-demand - Eliminate unused field warnings and reduce code complexity - Maintain all test functionality with cleaner design
This commit is contained in:
parent
01bcda10d0
commit
bde6181820
3 changed files with 31 additions and 46 deletions
|
|
@ -2,9 +2,11 @@ mod common;
|
|||
|
||||
#[test]
|
||||
fn test_rate_limiting_with_concurrent_requests() {
|
||||
let env = common::setup_test_environment();
|
||||
let temp_dir = common::setup_test_environment();
|
||||
let port = 1967 + (std::process::id() % 1000) as u16;
|
||||
|
||||
// Create config with rate limiting enabled
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let config_content = format!(r#"
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
|
|
@ -13,13 +15,13 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
max_concurrent_requests = 1
|
||||
"#, env.content_path.display(), env.cert_path.display(), env.key_path.display(), env.port);
|
||||
std::fs::write(&env.config_path, config_content).unwrap();
|
||||
"#, temp_dir.path().join("content").display(), temp_dir.path().join("cert.pem").display(), temp_dir.path().join("key.pem").display(), port);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
// Start server binary with test delay to simulate processing time
|
||||
let mut server_process = std::process::Command::new(env!("CARGO_BIN_EXE_pollux"))
|
||||
.arg("--config")
|
||||
.arg(&env.config_path)
|
||||
.arg(&config_path)
|
||||
.arg("--test-processing-delay")
|
||||
.arg("1") // 1 second delay per request
|
||||
.spawn()
|
||||
|
|
@ -31,7 +33,7 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
// Spawn 5 concurrent client processes
|
||||
let mut handles = vec![];
|
||||
for _ in 0..5 {
|
||||
let url = format!("gemini://localhost:{}/test.gmi", env.port);
|
||||
let url = format!("gemini://localhost:{}/test.gmi", port);
|
||||
let handle = std::thread::spawn(move || {
|
||||
std::process::Command::new("python3")
|
||||
.arg("tests/gemini_test_client.py")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue