From 3a323cf7cce107422a9b0a0b8aa4ce0c4f1240db Mon Sep 17 00:00:00 2001 From: chiachangwang Date: Tue, 20 Jun 2023 08:46:17 +0000 Subject: [PATCH] Add some timeout for waiting proxy being updated [MUST_SLEEP]ActivityThread may not have time to set the updated proxy into properties yet and cause flaky. Wait for some time in the test to deflake the test. Bug: 286551100 Test: com.android.cts.net.HostsideVpnTests Change-Id: I74d3d7378adcf12c094cb9c0706579d6e0b0826b --- .../src/com/android/cts/net/hostside/VpnTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java index cd3b650b05..454940f035 100755 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java @@ -1726,10 +1726,21 @@ public class VpnTest { assertEquals(VpnManager.TYPE_VPN_SERVICE, ((VpnTransportInfo) ti).getType()); } - private void assertDefaultProxy(ProxyInfo expected) { + private void assertDefaultProxy(ProxyInfo expected) throws Exception { assertEquals("Incorrect proxy config.", expected, mCM.getDefaultProxy()); String expectedHost = expected == null ? null : expected.getHost(); String expectedPort = expected == null ? null : String.valueOf(expected.getPort()); + + // ActivityThread may not have time to set it in the properties yet which will cause flakes. + // Wait for some time to deflake the test. + int attempt = 0; + while (!(Objects.equals(expectedHost, System.getProperty("http.proxyHost")) + && Objects.equals(expectedPort, System.getProperty("http.proxyPort"))) + && attempt < 300) { + attempt++; + Log.d(TAG, "Wait for proxy being updated, attempt=" + attempt); + Thread.sleep(100); + } assertEquals("Incorrect proxy host system property.", expectedHost, System.getProperty("http.proxyHost")); assertEquals("Incorrect proxy port system property.", expectedPort,