Fix flaky test RepeatedSetup_NoRedundantPrivateDnsValidation
There is a time gap between the time when PrivateDnsConfiguration
reports onPrivateDnsValidationEvent and the time when
PrivateDnsConfiguration updates its map which is used for tracking
validation threads. If the test starts a subsequent setup (which expects
the resolver to begin a new validation) before PrivateDnsConfiguration
updates the map, the expected validation won't start because
PrivateDnsConfiguration thinks the previous validation hasn't finished.
This change is a workaround which adds waiting time to avoid the timing
issue, and the test running time increases 300ms.
Bug: 150678049
Bug: 151990391
Test: resolv_integration_test passed
Merged-In: I176d7d20b7edc79b37b954602961c149aef64348
Change-Id: I9d9a456dd3a030eea8efc8d761e295ee7a4f179d
(cherry picked from commit 5fa66eac6c92f50ff73b9b65760b1f2418221ae5)
diff --git a/tests/resolv_integration_test.cpp b/tests/resolv_integration_test.cpp
index 0286310..76857cb 100644
--- a/tests/resolv_integration_test.cpp
+++ b/tests/resolv_integration_test.cpp
@@ -4246,6 +4246,16 @@
const std::string addr1 = getUniqueIPv4Address(); // For a workable DNS server.
const std::string addr2 = getUniqueIPv4Address(); // For an unresponsive DNS server.
const std::string unusable_addr = getUniqueIPv4Address();
+ const auto waitForPrivateDnsStateUpdated = []() {
+ // A buffer time for the PrivateDnsConfiguration instance to update its map,
+ // mPrivateDnsValidateThreads, which is used for tracking validation threads.
+ // Since there is a time gap between when PrivateDnsConfiguration reports
+ // onPrivateDnsValidationEvent and when PrivateDnsConfiguration updates the map, this is a
+ // workaround to avoid the test starts a subsequent resolver setup during the time gap.
+ // TODO: Report onPrivateDnsValidationEvent after all the relevant updates are complete.
+ // Reference to b/152009023.
+ std::this_thread::sleep_for(20ms);
+ };
test::DNSResponder dns1(addr1);
test::DNSResponder dns2(addr2);
@@ -4288,6 +4298,8 @@
parcel.caCertificate = config.tlsName.empty() ? "" : kCaCert;
const bool dnsModeChanged = (TlsNameLastTime != config.tlsName);
+
+ waitForPrivateDnsStateUpdated();
ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel));
for (const auto& serverAddr : parcel.tlsServers) {
@@ -4316,10 +4328,12 @@
}
// Repeated setups make no effect in strict mode.
+ waitForPrivateDnsStateUpdated();
ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel));
if (config.tlsName.empty()) {
EXPECT_TRUE(WaitForPrivateDnsValidation(unusable_addr, false));
}
+ waitForPrivateDnsStateUpdated();
ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel));
if (config.tlsName.empty()) {
EXPECT_TRUE(WaitForPrivateDnsValidation(unusable_addr, false));