OSDN Git Service

ConnectivityServiceTest: fix testAvoidBadWifiSettings
authorHugo Benichi <hugobenichi@google.com>
Tue, 15 Nov 2016 04:42:34 +0000 (13:42 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Thu, 26 Jan 2017 09:52:18 +0000 (18:52 +0900)
commitd49596f479d19b1f2decd1c71fb7abbc85682d55
treef456a088341232a75ff11c50f999e4577cd539a8
parentb038044758b2699f22b1215fe3a7ac4ed9a7a15a
ConnectivityServiceTest: fix testAvoidBadWifiSettings

This patch introduces an assertEventuallyThat helper function in
ConnectivityServiceTest which given a boolean function retries until the
function returns true or until a maximum retry time is reached.

This function is used to fix flakyness of testAvoidBadWifiSetting where
the Message posted by reevaluate() could reach the Handler's
MessageQueue after waitForIdle takes effect, resulting in the test to
fail.

Instead of fixing the flakyness by introdcing hard sleep times,
assertEventuallyThat is used to reduce the overall test time.

With this change the test has been observed to pass with 100% success
rate over 50000 invocations.

Test: $ runtest frameworks-net
Bug: 32561414

(cherry picked from commit 99c8294ef0c7a720364abb5884063e0a9d1bb5fe)

Change-Id: If41a24989d5f65aeb439f68741f511b5eb53b18d
tests/net/java/com/android/server/ConnectivityServiceTest.java