From 992588ca30e503436a0486b659f9f0ff57ce96f1 Mon Sep 17 00:00:00 2001 From: Michael Plass Date: Mon, 4 Dec 2017 11:39:13 -0800 Subject: [PATCH] Fix flaky WifiTrackerTest The rssiChangeBroadcastShouldUpdateConnectedAp uses two CountDownLatch instances to synchronize the events on the main thread and the handler thread. The "latch" informs the main thread that mockWifiManager.getConnectionInfo() has been called and allows it to proceed, and "mAccessPointsChangedLatch" notes that onAccessPointsChanged is called. But mAccessPointsChangedLatch was assigned after "latch" released the main thread, so that on occasion the main thread could try to use it before this assignment, causing the timeout. Move the assignment of mAccessPointsChangedLatch to before the body of the test to prevent this race. Bug: 70163367 Test: runtest --path frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java Change-Id: I62c1ef9a2155ffbd08b5e07e94723b28102d1f6d --- .../integ/src/com/android/settingslib/wifi/WifiTrackerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java index e64fc75bbba92..6615b8c02297d 100644 --- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java @@ -723,9 +723,9 @@ public class WifiTrackerTest { CountDownLatch latch = new CountDownLatch(1); // Once the new info has been fetched, we need to wait for the access points to be copied + mAccessPointsChangedLatch = new CountDownLatch(1); doAnswer(invocation -> { latch.countDown(); - mAccessPointsChangedLatch = new CountDownLatch(1); return info; }).when(mockWifiManager).getConnectionInfo();