Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06cfb443 authored by Mike Yu's avatar Mike Yu
Browse files

Fix flaky test PrivateDnsDohTest.ExcessDnsRequests

The test is flaky becuase the doh flag in DeviceConfig is
sometimes reset by someone else during the test. To fix
that, we have to make sure that the flag is set to 1 whenever
a network is created or destroyed.

This change also has some minor fixes.

Bug: 233024050
Test: atest
Change-Id: If4d10c3f37b120dea367af9362dde3d90cc7309c
parent 8366edca
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -284,11 +284,11 @@ class BasePrivateDnsTest : public BaseTest {

  protected:
    void SetUp() override {
        mDohScopedProp = make_unique<ScopedSystemProperties>(kDohFlag, "1");
        mDohScopedProp = std::make_unique<ScopedSystemProperties>(kDohFlag, "1");
        mDohQueryTimeoutScopedProp =
                make_unique<ScopedSystemProperties>(kDohQueryTimeoutFlag, "1000");
                std::make_unique<ScopedSystemProperties>(kDohQueryTimeoutFlag, "1000");
        unsigned int expectedProbeTimeout = kExpectedDohValidationTimeWhenTimeout.count();
        mDohProbeTimeoutScopedProp = make_unique<ScopedSystemProperties>(
        mDohProbeTimeoutScopedProp = std::make_unique<ScopedSystemProperties>(
                kDohProbeTimeoutFlag, std::to_string(expectedProbeTimeout));
        BaseTest::SetUp();

@@ -852,6 +852,10 @@ TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {
    ASSERT_TRUE(dns_ipv6.startServer());
    ASSERT_TRUE(dot_ipv6.startServer());
    ASSERT_TRUE(doh_ipv6.startServer());

    // It might already take several seconds before we are here. Add a ScopedSystemProperties
    // to ensure the doh flag is 1 before creating a new network.
    ScopedSystemProperties sp1(kDohFlag, "1");
    mDnsClient.SetupOemNetwork(TEST_NETID_2);

    parcel.netId = TEST_NETID_2;
@@ -870,6 +874,10 @@ TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {

    // Expect two queries: one for DoH probe and the other one for kQueryHostname.
    EXPECT_EQ(doh_ipv6.queries(), 2);

    // Add a ScopedSystemProperties here as well since DnsResolver will update its cached flags
    // when the networks is removed.
    ScopedSystemProperties sp2(kDohFlag, "1");
    mDnsClient.TearDownOemNetwork(TEST_NETID_2);

    // The DnsResolver will reconnect to the DoH server for the query that gets blocked at
@@ -1058,13 +1066,13 @@ TEST_F(PrivateDnsDohTest, SessionResumption) {
    const int initial_max_idle_timeout_ms = 1000;
    for (const auto& flag : {"0", "1"}) {
        SCOPED_TRACE(fmt::format("flag: {}", flag));
        auto sp = make_unique<ScopedSystemProperties>(kDohSessionResumptionFlag, flag);
        ScopedSystemProperties sp(kDohSessionResumptionFlag, flag);

        // Each loop takes around 3 seconds, if the system property "doh" is reset in the middle
        // of the first loop, this test will fail when running the second loop because DnsResolver
        // updates its "doh" flag when resetNetwork() is called. Therefore, add another
        // ScopedSystemProperties for "doh" to make the test more robust.
        auto sp2 = make_unique<ScopedSystemProperties>(kDohFlag, "1");
        ScopedSystemProperties sp2(kDohFlag, "1");
        resetNetwork();

        ASSERT_TRUE(doh.stopServer());