Fix 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 Review URL: https://codereview.chromium.org/1634693002 Cr-Commit-Position: refs/heads/master@{#371477}
Showing
Please register or sign in to comment