summaryrefslogtreecommitdiff
path: root/tests/dns_tls_test.cpp
diff options
context:
space:
mode:
authorBen Schwartz <bemasc@google.com>2019-01-22 17:32:17 -0500
committerAli B <abittin@gmail.com>2019-07-02 14:35:13 +0300
commit430ecb0cd7e9ef98caf71f0c7740bf75504be72b (patch)
tree15f0144160c3068e8376a207be9bbba3e1908050 /tests/dns_tls_test.cpp
parent70e5a69adf6ab2116c7c029cade8664edf669238 (diff)
Fix DnsTlsSocket fast shutdown pathp9.0
Previously, DnsTlsSocket's destructor told the loop thread to perform a clean shutdown by closing an IPC file descriptor. However, the IPC file descriptor is now an eventfd, which does not alert the listening thread when it is closed. This change uses the eventfd counter's sign bit as an indication that the destructor is requesting an immediate close. Test: Includes regression test. Bug: 123212403 Bug: 124058672 Bug: 122856181 Change-Id: I6edc26bf504cbfbba7d055b1f8e52ac70e02c6e0 Merged-In: I6edc26bf504cbfbba7d055b1f8e52ac70e02c6e0 (cherry picked from commit 83eccadc7e9d0ee0f75aab980cfdc2159c4c98a2)
Diffstat (limited to 'tests/dns_tls_test.cpp')
-rw-r--r--tests/dns_tls_test.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/dns_tls_test.cpp b/tests/dns_tls_test.cpp
index bb5bfe56..b7fb3a45 100644
--- a/tests/dns_tls_test.cpp
+++ b/tests/dns_tls_test.cpp
@@ -28,6 +28,8 @@
#include "dns/IDnsTlsSocketFactory.h"
#include "dns/IDnsTlsSocketObserver.h"
+#include "dns_responder/dns_tls_frontend.h"
+
#include <chrono>
#include <arpa/inet.h>
#include <android-base/macros.h>
@@ -871,5 +873,44 @@ TEST(QueryMapTest, FillHole) {
EXPECT_FALSE(map.recordQuery(makeSlice(QUERY)));
}
+class StubObserver : public IDnsTlsSocketObserver {
+ public:
+ bool closed = false;
+ void onResponse(std::vector<uint8_t>) override {}
+
+ void onClosed() override { closed = true; }
+};
+
+TEST(DnsTlsSocketTest, SlowDestructor) {
+ constexpr char tls_addr[] = "127.0.0.3";
+ constexpr char tls_port[] = "8530"; // High-numbered port so root isn't required.
+ // This test doesn't perform any queries, so the backend address can be invalid.
+ constexpr char backend_addr[] = "192.0.2.1";
+ constexpr char backend_port[] = "1";
+
+ test::DnsTlsFrontend tls(tls_addr, tls_port, backend_addr, backend_port);
+ ASSERT_TRUE(tls.startServer());
+
+ DnsTlsServer server;
+ parseServer(tls_addr, 8530, &server.ss);
+
+ StubObserver observer;
+ ASSERT_FALSE(observer.closed);
+ DnsTlsSessionCache cache;
+ auto socket = std::make_unique<DnsTlsSocket>(server, MARK, &observer, &cache);
+ ASSERT_TRUE(socket->initialize());
+
+ // Test: Time the socket destructor. This should be fast.
+ auto before = std::chrono::steady_clock::now();
+ socket.reset();
+ auto after = std::chrono::steady_clock::now();
+ auto delay = after - before;
+ ALOGV("Shutdown took %lld ns", delay / std::chrono::nanoseconds{1});
+ EXPECT_TRUE(observer.closed);
+ // Shutdown should complete in milliseconds, but if the shutdown signal is lost
+ // it will wait for the timeout, which is expected to take 20seconds.
+ EXPECT_LT(delay, std::chrono::seconds{5});
+}
+
} // end of namespace net
} // end of namespace android