Fix AssistDataRequesterTest Flakiness
There's a race condition between setting `mRequestCompleted = true`
and asserts its value as true in #assertReceivedDataCount.
Fix the flakiness by updating `mRequestCompleted` whenever getting
the callback (without handling it asynchronously).
Bug: 280107567
Bug: 296229082
Test: run the test over 200 times
Change-Id: I04dfa87c762fd9ee7dfcb9d5dd5982780f43356c
Merged-In: I04dfa87c762fd9ee7dfcb9d5dd5982780f43356c
(cherry picked from commit 6c1126780d45c62b73c170523ccf539030fbdf84)
diff --git a/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java b/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
index 7b4392b..56c3ec0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/AssistDataRequesterTest.java
@@ -317,7 +317,8 @@
assertEquals("Expected " + numPendingScreenshots + " pending screenshots, got "
+ mDataRequester.getPendingScreenshotCount(),
numPendingScreenshots, mDataRequester.getPendingScreenshotCount());
- assertFalse("Expected request NOT completed", mCallbacks.mRequestCompleted);
+ assertEquals("Expected request NOT completed, unless no pending data",
+ numPendingData == 0 && numPendingScreenshots == 0, mCallbacks.mRequestCompleted);
mGate.countDown();
waitForIdle(mHandler);
assertEquals("Expected " + numReceivedData + " data, received "
@@ -376,14 +377,7 @@
@Override
public void onAssistRequestCompleted() {
- mHandler.post(() -> {
- try {
- mGate.await(10, TimeUnit.SECONDS);
- mRequestCompleted = true;
- } catch (InterruptedException e) {
- Log.e(TAG, "Failed to wait", e);
- }
- });
+ mRequestCompleted = true;
}
}
}