InputDispatcher_test: Fix flakiness when verifying traced events
Fix the flakiness when verifying all events are traced by doing the
verification before stopping Dispatcher.
When verifying traced events, we wait for all expected events to be
traced. If the Dispatcher is stopped before this waiting process, it's
possible that the InputTracer's thread is also stopped before it can
write all queued events into the backend. We eliminate the race
condition between stopping the Dispatcher and verifying the events by
doing the verification first.
Bug: 210460522
Bug: 323347575
Test: atest inputflinger_tests --rerun-until-failure
Change-Id: I454ca85174c97c848f1da45157d5b993935a261e
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index b85976e..1c37da0 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -684,10 +684,10 @@
}
void TearDown() override {
+ ASSERT_NO_FATAL_FAILURE(gVerifyingTrace->verifyExpectedEventsTraced());
ASSERT_EQ(OK, mDispatcher->stop());
mFakePolicy.reset();
mDispatcher.reset();
- ASSERT_NO_FATAL_FAILURE(gVerifyingTrace->verifyExpectedEventsTraced());
}
/**