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

Commit a4d7bb98 authored by Mike Yu's avatar Mike Yu
Browse files

Fix PrivateDnsDohTest.ExcessDnsRequests not to interfere other tests

Before this change, DnsResolver reconnects the server after
this test ends. This causes other tests being flaky, especially
for those test that check the number of connections. A known
example is running PrivateDnsDohTest.SessionResumption after
PrivateDnsDohTest.ExcessDnsRequests.

Therefore, this change adds some code in the test to prevent it.

Bug: 222023286
Test: run resolv_integration_test64
      --gtest_filter="*SessionResumption*:*ExcessDnsRequests*"
Change-Id: Id11eb8d984128bc2b336d2939ae129eebeb17807
parent f696ba34
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -744,6 +744,7 @@ TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {
    for (const auto& fd : fds) {
        expectAnswersValid(fd, AF_INET6, kQueryAnswerAAAA);
    }
    EXPECT_TRUE(doh.block_sending(false));

    // There are some queries that fall back to DoT rather than UDP since the DoH client rejects
    // any new DNS requests when the capacity is full.
@@ -780,6 +781,21 @@ TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {
    // Expect two queries: one for DoH probe and the other one for kQueryHostname.
    EXPECT_EQ(doh_ipv6.queries(), 2);
    mDnsClient.TearDownOemNetwork(TEST_NETID_2);

    // The DnsResolver will reconnect to the DoH server for the query that gets blocked at
    // dispatcher sending channel. However, there's no way to know when the reconnection will start.
    // We have to periodically send a DNS request to check it. After the reconnection starts, the
    // DNS query will be sent to the Doh server instead of the cleartext DNS server. Then, we
    // are safe to end the test. Otherwise, the reconnection will interfere other tests.
    EXPECT_EQ(doh.queries(), 0);
    for (int i = 0; i < 50; i++) {
        sleep_for(milliseconds(100));
        int fd = resNetworkQuery(TEST_NETID, kQueryHostname, ns_c_in, ns_t_aaaa,
                                 ANDROID_RESOLV_NO_CACHE_LOOKUP);
        expectAnswersValid(fd, AF_INET6, kQueryAnswerAAAA);
        if (doh.queries() > 0) break;
    }
    EXPECT_GT(doh.queries(), 0);
}

// Tests the scenario where the DnsResolver runs out of QUIC connection data limit.