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 b54c8cffa889a9c0debbb7f05c47ede670babd45)

Change-Id: If41a24989d5f65aeb439f68741f511b5eb53b18d
1 file changed
tree: 2016bc826fff6562599e45995fd3bd2a28f83f7f
  1. core/
  2. services/
  3. tests/