Skip to content

Commit 0533bd2

Browse files
Fixed flaky unit test (#5654)
This PR fixes a test that is sporadically failing in CI. The problem is that two unit tests (the older `login_and_cancel_chatgpt` and a recently added `login_chatgpt_includes_forced_workspace_query_param`) exercise code paths that start the login server. The server binds to a hard-coded localhost port number, so attempts to start more than one server at the same time will fail. If these two tests happen to run concurrently, one of them will fail. To fix this, I've added a simple mutex. We can use this same mutex for future tests that use the same pattern.
1 parent 6af83d8 commit 0533bd2

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

codex-rs/Cargo.lock

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

codex-rs/app-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ base64 = { workspace = true }
4747
core_test_support = { workspace = true }
4848
os_info = { workspace = true }
4949
pretty_assertions = { workspace = true }
50+
serial_test = { workspace = true }
5051
tempfile = { workspace = true }
5152
toml = { workspace = true }
5253
wiremock = { workspace = true }

codex-rs/app-server/tests/suite/login.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use codex_app_server_protocol::LoginChatGptResponse;
1313
use codex_app_server_protocol::LogoutChatGptResponse;
1414
use codex_app_server_protocol::RequestId;
1515
use codex_login::login_with_api_key;
16+
use serial_test::serial;
1617
use tempfile::TempDir;
1718
use tokio::time::timeout;
1819

@@ -94,6 +95,8 @@ async fn logout_chatgpt_removes_auth() {
9495
}
9596

9697
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
98+
// Serialize tests that launch the login server since it binds to a fixed port.
99+
#[serial(login_port)]
97100
async fn login_and_cancel_chatgpt() {
98101
let codex_home = TempDir::new().unwrap_or_else(|e| panic!("create tempdir: {e}"));
99102
create_config_toml(codex_home.path()).unwrap_or_else(|err| panic!("write config.toml: {err}"));
@@ -208,6 +211,8 @@ async fn login_chatgpt_rejected_when_forced_api() {
208211
}
209212

210213
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
214+
// Serialize tests that launch the login server since it binds to a fixed port.
215+
#[serial(login_port)]
211216
async fn login_chatgpt_includes_forced_workspace_query_param() {
212217
let codex_home = TempDir::new().unwrap_or_else(|e| panic!("create tempdir: {e}"));
213218
create_config_toml_forced_workspace(codex_home.path(), "ws-forced")

0 commit comments

Comments
 (0)