Skip to content

Commit fc65bdd

Browse files
Fix IPC server test timing for CI environments
Add startup sleeps and increase poll timeouts in IPC server unit tests to prevent flaky failures on slower CI runners.
1 parent 445c0d6 commit fc65bdd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/ipc/server.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ mod tests {
188188
assert!(server.is_running());
189189
assert_eq!(server.port(), port);
190190

191+
// Give the server listener thread time to start accepting
192+
std::thread::sleep(Duration::from_millis(200));
193+
191194
// Try to connect
192195
let stream = TcpStream::connect_timeout(
193196
&format!("127.0.0.1:{}", port).parse().unwrap(),
@@ -201,6 +204,9 @@ mod tests {
201204
let port = find_available_port();
202205
let server = IpcServer::start_on_port(port).expect("Failed to start server");
203206

207+
// Give the server listener thread time to start accepting
208+
std::thread::sleep(Duration::from_millis(200));
209+
204210
// Connect and send a command
205211
let mut stream = TcpStream::connect_timeout(
206212
&format!("127.0.0.1:{}", port).parse().unwrap(),
@@ -218,12 +224,12 @@ mod tests {
218224

219225
// Poll for the command (give the server thread time to process)
220226
let mut received = None;
221-
for _ in 0..50 {
227+
for _ in 0..100 {
222228
if let Some(cmd) = server.poll_command() {
223229
received = Some(cmd);
224230
break;
225231
}
226-
std::thread::sleep(Duration::from_millis(10));
232+
std::thread::sleep(Duration::from_millis(20));
227233
}
228234

229235
assert!(received.is_some(), "Should receive command via channel");
@@ -256,6 +262,9 @@ mod tests {
256262
let port = find_available_port();
257263
let server = IpcServer::start_on_port(port).expect("Failed to start server");
258264

265+
// Give the server listener thread time to start accepting
266+
std::thread::sleep(Duration::from_millis(200));
267+
259268
let commands = vec![IpcCommand::Ping, IpcCommand::GetState, IpcCommand::Ping];
260269

261270
for cmd in commands {
@@ -274,12 +283,12 @@ mod tests {
274283

275284
// Poll for command
276285
let mut received = None;
277-
for _ in 0..50 {
286+
for _ in 0..100 {
278287
if let Some(c) = server.poll_command() {
279288
received = Some(c);
280289
break;
281290
}
282-
std::thread::sleep(Duration::from_millis(10));
291+
std::thread::sleep(Duration::from_millis(20));
283292
}
284293

285294
assert!(received.is_some(), "Should receive command");
@@ -307,6 +316,9 @@ mod tests {
307316
let port = find_available_port();
308317
let _server = IpcServer::start_on_port(port).expect("Failed to start server");
309318

319+
// Give the server listener thread time to start accepting
320+
std::thread::sleep(Duration::from_millis(200));
321+
310322
let mut stream = TcpStream::connect_timeout(
311323
&format!("127.0.0.1:{}", port).parse().unwrap(),
312324
Duration::from_secs(2),

0 commit comments

Comments
 (0)