diff --git a/test/integration/quic_http_integration_test.cc b/test/integration/quic_http_integration_test.cc index c11b91987849..41e7e6c92ce3 100644 --- a/test/integration/quic_http_integration_test.cc +++ b/test/integration/quic_http_integration_test.cc @@ -1392,16 +1392,16 @@ TEST_P(QuicHttpIntegrationTest, DeferredLoggingWithRetransmission) { // Temporarily prevent server from writing packets (i.e. to respond to downstream) // to simulate packet loss and trigger retransmissions. - SocketInterfaceSwap socket_swap(upstreamProtocol() == Http::CodecType::HTTP3 - ? Network::Socket::Type::Datagram - : Network::Socket::Type::Stream); - Network::IoSocketError* ebadf = Network::IoSocketError::getIoSocketEbadfInstance(); - socket_swap.write_matcher_->setDestinationPort(lookupPort("http")); - socket_swap.write_matcher_->setWriteOverride(ebadf); - upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true); - absl::SleepFor(absl::Milliseconds(500 * TSAN_TIMEOUT_FACTOR)); - // Allow the response to be sent downstream again. - socket_swap.write_matcher_->setWriteOverride(nullptr); + { + SocketInterfaceSwap socket_swap(downstreamProtocol() == Http::CodecType::HTTP3 + ? Network::Socket::Type::Datagram + : Network::Socket::Type::Stream); + Network::IoSocketError* ebadf = Network::IoSocketError::getIoSocketEbadfInstance(); + socket_swap.write_matcher_->setDestinationPort(lookupPort("http")); + socket_swap.write_matcher_->setWriteOverride(ebadf); + upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true); + timeSystem().advanceTimeWait(std::chrono::seconds(TSAN_TIMEOUT_FACTOR)); + } ASSERT_TRUE(response->waitForEndStream()); codec_client_->close();