Fix race condition in testSendOrderedBroadcast1
HighPriorityBroadcastReceiver is supposed to get its broadcast, then
wait for notification from the test before completing its onReceive.
However, there is no synchronization around setting the
mReceivedBroadcast in ResultReceiver.onReceive() and starting the wait
in its own onReceive. This means that in testSendOrderedBroadcast1 there
is a race condition where highPriorityReceiver.hasReceivedBroadCast()
in the first PollingCheck is true, causing it to notify() before the
onReceive on highPriorityReceiver has gotten to wait().
When that happens, highPriorityReceiver never gets notified again.
This causes it to block the ordered broadcast, meaning the
lowPriorityReceiver never gets it, making the second PollingCheck never
succeed and instead timing out.
Adding synchronization around the call to super.onReceive in
HighPriorityBroadcastReceiver resolves this.
Change-Id: Icb3854be52cb5c6be2d52dd54930b4852d8fc5d4
1 file changed