From dfe9eeb15c70d2ff0b70fb4651b29fa500a30375 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Mon, 21 Jul 2025 11:47:43 +0800 Subject: [PATCH] fix: unit test failed by adding necessary sleep function to ensure the time seqence (#6548) Signed-off-by: zyy17 --- src/common/event-recorder/src/recorder.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/event-recorder/src/recorder.rs b/src/common/event-recorder/src/recorder.rs index a1287aa1d5..3c887aa455 100644 --- a/src/common/event-recorder/src/recorder.rs +++ b/src/common/event-recorder/src/recorder.rs @@ -466,11 +466,14 @@ mod tests { ); event_recorder.record(Box::new(TestEvent {})); - // Cancel the event recorder to flush the buffer. + // Sleep for a while to let the event be sent to the event handler. + sleep(Duration::from_millis(500)).await; + + // Close the event recorder to flush the buffer. event_recorder.close(); // Sleep for a while to let the background task process the event. - sleep(Duration::from_millis(100)).await; + sleep(Duration::from_millis(500)).await; if let Some(handle) = event_recorder.handle.take() { assert!(handle.await.is_ok()); @@ -508,11 +511,14 @@ mod tests { event_recorder.record(Box::new(TestEvent {})); + // Sleep for a while to let the event be sent to the event handler. + sleep(Duration::from_millis(500)).await; + // Close the event recorder to flush the buffer. event_recorder.close(); // Sleep for a while to let the background task process the event. - sleep(Duration::from_millis(100)).await; + sleep(Duration::from_millis(500)).await; if let Some(handle) = event_recorder.handle.take() { assert!(handle.await.unwrap_err().is_panic());