[DocsUI] add TestNotificationService.rendezvous
This is a test only change.
The TestNotificationService (TNS) is instantiated indirectly, by being
declared in the tests/AndroidManifest.xml file. Other test code (like
FileDeleteUiTest) sends the TNS intents but, prior to this commit,
sending such intents was racing with the TNS (which can be in a separate
process) actually being ready to receive them. Specifically, it was
racing with TNS.onCreate calling registerReceiver.
TNS has two modes (see its "enum MODE" type): CANCEL_MODE and
EXECUTION_MODE. The default mode is CANCEL_MODE but the FileCopyUiTest
and FileDeleteUiTest setUpTest methods try to change modes by sending an
ACTION_CHANGE_EXECUTION_MODE intent. Prior to this commit, this intent
was sometimes ignored, if TNS wasn't ready, and those tests were flaky.
When TNS is in CANCEL_MODE, TNS.onNotificationPosted would trigger a
notification's actions, including the cancelIntent prepared by Job's
createProgressBuilder, normally triggerable as an optional notification
action. The FileDeleteUiTest would set up 1000 files, start a job to
delete them and assert that we finished with 0 files. But that job was
racing the cancellation and so FileDeleteUiTest was flaky, failing if
the cancellation won the race.
Separately, CancelFromNotificationUiTest remains flaky before and after
this commit, because TNS.doCancel returns early when TNS.isStartProgress
returns false (i.e. when there is no progress bar visible), but I think
that's a separate problem.
The CancelFromNotificationUiTest sends ACTION_CHANGE_CANCEL_MODE instead
of ACTION_CHANGE_EXECUTION_MODE, which is basically a no-op because, as
alluded to earlier, the TNS.mCurrentMode field is initialized to
CANCEL_MODE. Still, fixing CancelFromNotificationUiTest to also
explicitly rendezvous shouldn't hurt and sets up a future commit where
we can initialize the field to DO_NOTHING_MODE instead of CANCEL_MODE,
which might be more robust.
Bug: 437215252
Bug: 440933276
Flag: EXEMPT test only change
Test: atest DocumentsUIGoogleTests:com.android.documentsui.FileDeleteUiTest
Change-Id: I5061f331cd260bc8fd3f64123237b535f41a2c1a
4 files changed