DescriptionFix race condition in InstallerDelegateTest.
Remove the unnecessary and dangerous polling in startMonitoring(). mTestDelegate.mIsRunning is set directly in start(), so waiting for mTestDelegate.isRunning() does not guarantee anything. However, it does introduce the possibility of a race if the mHandler.postDelayed() call in mTestDelegate.start() switches threads.
Precisely, if mHandler.postDelayed() stays in the same thread, or causes uninteresting thread switches, the following happens in startMonitoring:
mTestDelegate.start ->
mIsRunning = true;
...
CriteriaHelper.pollForCriteria ->
mTestDeleted.isRunning() == true, exit immediately.
On the other hand, if there is an interesting thread switch in mHandler.postDelayed(), then we could have
mTestDelegate.start ->
mIsRunning = true;
mHandler.postDelayed()
... stuff happens ...
mTestDelegate.run() is called
mIsRunning = false;
... more stuff happens ..
(now back to main test thread)
CriteriaHelper.pollForCriteria ->
mTestDeleted.isRunning() == false, loop until timeout and the test fails.
Before removing this poll, running locally the test occasionally retried tests on a nexus 4; after removing it it ran 20 times successfully with no retries. I think we have slightly higher confidence now that it won't flake on the build.
BUG=542627
Committed: https://crrev.com/b4ffd219c5633ddd3eaa4ee20832e83cc0320e31
Cr-Commit-Position: refs/heads/master@{#371477}
Patch Set 1 #Patch Set 2 : Remove flaky test #Messages
Total messages: 11 (6 generated)
|