From e97cea612728df25b8ba0b2d2f3ef7bd9e396faa Mon Sep 17 00:00:00 2001 From: Ante Date: Fri, 7 Oct 2022 20:26:02 +0000 Subject: Fix flaky test test_hal_error_event This test would fail on average every 2nd run when ran on a device. This was due to a race condition between UwbEvent::ERROR event and the test method dropping and thus invoking assert!(self.expected_calls.lock().unwrap().is_empty()) from mock_adaptation Drop too early. To fix it I sent another event UwbEvent::CLOSE_CPLT at the end which is processed only after the ERROR event, and since sending CLOSE_CPLT event exits the dispatcher this enables calling dispatcher.wait_for_exit() which then makes sure the test method doesn't drop before both events get processed. Bug: 251879446 Test: atest libuwb_uci_rust_tests --rerun-until-failure 20 Change-Id: If30794d6cff3c0130b4675af0eead27777803df8 --- src/rust/uci/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/rust/uci/mod.rs') diff --git a/src/rust/uci/mod.rs b/src/rust/uci/mod.rs index 3458fc5..b9a8b23 100644 --- a/src/rust/uci/mod.rs +++ b/src/rust/uci/mod.rs @@ -655,7 +655,7 @@ mod tests { #[test] fn test_hal_error_event() { - let (dispatcher, hal_sender) = + let (mut dispatcher, hal_sender) = setup_dispatcher_and_return_hal_cb_sender(|mock_adaptation, mock_event_manager| { mock_adaptation.expect_hal_open(Ok(())); mock_adaptation.expect_core_initialization(Ok(())); @@ -667,9 +667,16 @@ mod tests { hal_sender .send(( HalCallback::Event { event: UwbEvent::ERROR, event_status: UwbStatus::FAILED }, + chip_id.clone(), + )) + .unwrap(); + hal_sender + .send(( + HalCallback::Event { event: UwbEvent::CLOSE_CPLT, event_status: UwbStatus::OK }, chip_id, )) .unwrap(); + dispatcher.wait_for_exit().unwrap(); } #[test] -- cgit v1.2.3