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

Commit 20af0246 authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Remove the waiting time when restart test DoH servers am: b585d8b0 am: 6fe381f0 am: eefef36b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/2028243

Change-Id: I3943fbb30a7ed47c8c3d9a0c5968d59e1ca1ec0a
parents f80afed1 eefef36b
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ impl DohFrontend {
        backend_socket.connect(self.backend_socket_addr)?;
        backend_socket.set_nonblocking(true)?;

        let frontend_socket = std::net::UdpSocket::bind(self.listen_socket_addr)?;
        let frontend_socket = bind_udp_socket_retry(self.listen_socket_addr)?;
        frontend_socket.set_nonblocking(true)?;

        let clients = ClientMap::new(create_quiche_config(
@@ -473,3 +473,18 @@ fn build_pipe() -> Result<(File, File)> {
    }
    Err(anyhow::Error::new(std::io::Error::last_os_error()).context("build_pipe failed"))
}

// Can retry to bind the socket address if it is in use.
fn bind_udp_socket_retry(addr: std::net::SocketAddr) -> Result<std::net::UdpSocket> {
    for _ in 0..3 {
        match std::net::UdpSocket::bind(addr) {
            Ok(socket) => return Ok(socket),
            Err(e) if e.kind() == std::io::ErrorKind::AddrInUse => {
                warn!("Binding socket address {} that is in use. Try again", addr);
                std::thread::sleep(Duration::from_millis(50));
            }
            Err(e) => return Err(anyhow::anyhow!(e)),
        }
    }
    Err(anyhow::anyhow!(std::io::Error::last_os_error()))
}
+0 −14
Original line number Diff line number Diff line
@@ -791,9 +791,6 @@ TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {
    const int initial_max_idle_timeout_ms = 2000;
    ASSERT_TRUE(doh.stopServer());
    EXPECT_TRUE(doh.setMaxIdleTimeout(initial_max_idle_timeout_ms));
    // Sleep a while to avoid binding socket failed.
    // TODO: Make DohFrontend retry binding sockets.
    sleep_for(milliseconds(100));
    ASSERT_TRUE(doh.startServer());

    auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
@@ -886,9 +883,6 @@ TEST_F(PrivateDnsDohTest, RunOutOfDataLimit) {

    ASSERT_TRUE(doh.stopServer());
    EXPECT_TRUE(doh.setMaxBufferSize(initial_max_data));
    // Sleep a while to avoid binding socket failed.
    // TODO: Make DohFrontend retry binding sockets.
    sleep_for(milliseconds(100));
    ASSERT_TRUE(doh.startServer());

    const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
@@ -938,8 +932,6 @@ TEST_F(PrivateDnsDohTest, RunOutOfStreams) {

    ASSERT_TRUE(doh.stopServer());
    EXPECT_TRUE(doh.setMaxStreamsBidi(initial_max_streams_bidi));
    // Sleep a while to avoid binding socket failed.
    sleep_for(milliseconds(100));
    ASSERT_TRUE(doh.startServer());

    const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
@@ -978,8 +970,6 @@ TEST_F(PrivateDnsDohTest, ReconnectAfterIdleTimeout) {

    ASSERT_TRUE(doh.stopServer());
    EXPECT_TRUE(doh.setMaxIdleTimeout(initial_max_idle_timeout_ms));
    // Sleep a while to avoid binding socket failed.
    sleep_for(milliseconds(100));
    ASSERT_TRUE(doh.startServer());

    const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
@@ -1062,8 +1052,6 @@ TEST_F(PrivateDnsDohTest, SessionResumption) {

        ASSERT_TRUE(doh.stopServer());
        EXPECT_TRUE(doh.setMaxIdleTimeout(initial_max_idle_timeout_ms));
        // Sleep a while to avoid binding socket failed.
        sleep_for(milliseconds(100));
        ASSERT_TRUE(doh.startServer());

        const auto parcel = DnsResponderClient::GetDefaultResolverParamsParcel();
@@ -1112,8 +1100,6 @@ TEST_F(PrivateDnsDohTest, RemoteConnectionClosed) {
    // Make the server close the connection. This will also reset the stats, so the doh query
    // count below is still 2 rather than 4.
    ASSERT_TRUE(doh.stopServer());
    // Sleep a while to avoid binding socket failed.
    sleep_for(milliseconds(100));
    ASSERT_TRUE(doh.startServer());

    EXPECT_NO_FAILURE(sendQueryAndCheckResult());