From 4ae1387146062c63fbb01d54feb4edb36a7e142e Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 4 Jun 2024 16:04:58 +0900 Subject: [PATCH] Refresh time before connectivity tests After checking that networking is available, force a time sync. This should avoid flakes where time changes during tests, for example for tests using test settings like test_url_expiration_time in NetworkMonitor. Fixes: 342489019 Test: atest Change-Id: I0c07440679bc14dcf5cddf55fb1391d3ed76feba --- .../android/testutils/ConnectivityTestTargetPreparer.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt b/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt index 600a62359a..6d03042dc1 100644 --- a/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt +++ b/staticlibs/testutils/host/com/android/testutils/ConnectivityTestTargetPreparer.kt @@ -61,6 +61,7 @@ open class ConnectivityTestTargetPreparer : BaseTargetPreparer() { setUpdaterNetworkingEnabled(testInfo, enableChain = true, enablePkgs = UPDATER_PKGS.associateWith { false }) runPreparerApk(testInfo) + refreshTime(testInfo) } private fun runPreparerApk(testInfo: TestInformation) { @@ -141,6 +142,14 @@ open class ConnectivityTestTargetPreparer : BaseTargetPreparer() { .contains(":deny") } + private fun refreshTime(testInfo: TestInformation,) { + // Forces a synchronous time refresh using the network. Time is fetched synchronously but + // this does not guarantee that system time is updated when it returns. + // This avoids flakes where the system clock rolls back, for example when using test + // settings like test_url_expiration_time in NetworkMonitor. + testInfo.exec("cmd network_time_update_service force_refresh") + } + override fun tearDown(testInfo: TestInformation, e: Throwable?) { if (isTearDownDisabled) return installer.tearDown(testInfo, e)