Skip to content

Commit 2f84189

Browse files
committed
fix(test): properly serialize env variable tests with serial_test crate
Add serial_test dependency and mark all tests that modify environment variables with #[serial_test::serial] to prevent race conditions when tests run in parallel. Fixed tests: - test_env_security_with_invalid_profile - test_env_security_with_valid_profiles - test_env_config_loading This resolves the flaky test failure in CI by ensuring these tests run one at a time instead of being ignored.
1 parent c98f3d7 commit 2f84189

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

Cargo.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mcp-security-middleware/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pulseengine-mcp-protocol = { workspace = true }
6161
tempfile = { workspace = true }
6262
assert_matches = { workspace = true }
6363
tokio-test = "0.4"
64+
serial_test = "3.0"
6465

6566
[features]
6667
default = ["auto-config"]

mcp-security-middleware/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ mod tests {
473473
}
474474

475475
#[test]
476+
#[serial_test::serial]
476477
fn test_env_config_loading() {
477478
unsafe {
478479
env::set_var("MCP_SECURITY_PROFILE", "development");

mcp-security-middleware/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ mod tests {
173173
}
174174

175175
#[test]
176-
#[ignore] // TODO: Fix race condition with parallel tests - use serial_test crate
176+
#[serial_test::serial]
177177
fn test_env_security_with_invalid_profile() {
178178
use std::env;
179179

@@ -192,6 +192,7 @@ mod tests {
192192
}
193193

194194
#[test]
195+
#[serial_test::serial]
195196
fn test_env_security_with_valid_profiles() {
196197
use std::env;
197198

0 commit comments

Comments
 (0)