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
This commit is contained in:
Remi NGUYEN VAN 2024-06-04 16:04:58 +09:00
commit 4ae1387146

View file

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