Add the ability to affect ordering in the tethering unit tests.

Currently, TestConnectivityManager immediately sends all
callbacks and broadcasts to the Tethering code as soon as the
test code makes any change.

This makes it impossible to affect the order in which those
events are delivered to the Tethering code, so it is not possible
to test for races.

Fix some of this as follows:
1. Make TestConnectivityManager post all its callbacks to the
   handlers that Tethering registered them with.
2. In TetheringTest, use the existing TestLooper object to
   advance time manually. Also use setUseRegisteredHandlers to
   ensure that the broadcasts are sent in order. This requires
   calling dispatchAll() after sending the broadcast to preserve
   the existing synchronous behaviour. Take advantage of that to
   remove lots of existing dispatchAll calls.
3. Add a TestLooper to UpstreamNetworkMonitorTest and use it.
   Keep the test passing by adding lots of mLooper.dispatchAll(),
   which is a bit ugly but probably acceptable given the
   additional coverage it provides.

This exposes an existing bug in the code where if upstream
selection is in automatic mode, and all CONNECTIVITY_ACTION
broadcasts are received before all NetworkCallbacks, the code
does not switch upstream.

In order to make the tests pass, re-order the CONNECTIVITY_ACTION
broadcasts with the NetworkCallbacks in TestConnectivityManager
so as not to trigger the bug. A future CL will make the order
configurable.

While I'm at it, switch TestConnectivityManager from HashMap to
ArrayMap, which is generally preferred for maps that do not
contain too many elements.

Bug: 173068192
Test: test-only change
Change-Id: I964f365c691fbc396ab0a87f292bd32b123011fe
3 files changed
tree: 55c20557c9359d2dd044ff6f0252fc464e6660cf
  1. tests/
  2. Tethering/
  3. .gitignore
  4. OWNERS
  5. PREUPLOAD.cfg
  6. TEST_MAPPING