From 95277f3c7344e537ad42835c64607339e1d3e6e9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 7 Mar 2016 09:34:37 -0600 Subject: add test to confirm on_pk() signal is fired in the main thread rather than the worker thread --- tests/adbd-client-test.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/adbd-client-test.cpp b/tests/adbd-client-test.cpp index 4fa16a8..ae0378b 100644 --- a/tests/adbd-client-test.cpp +++ b/tests/adbd-client-test.cpp @@ -53,9 +53,6 @@ protected: TEST_F(AdbdClientFixture, SocketPlumbing) { - const auto socket_path = m_tmpdir + "/test-socket-plumbing"; - g_message("socket_path is %s", socket_path.c_str()); - struct { const std::string request; const std::string expected_pk; @@ -68,18 +65,24 @@ TEST_F(AdbdClientFixture, SocketPlumbing) { "PK", "", AdbdClient::PKResponse::DENY, "NO" } }; + const auto main_thread = g_thread_self(); + + const auto socket_path = m_tmpdir + "/test-socket-plumbing"; + g_message("socket_path is %s", socket_path.c_str()); + for (const auto& test : tests) { - // make the AdbdClient and start listening for Requests + // start an AdbdClient that listens for PKRequests std::string pk; auto adbd_client = std::make_shared(socket_path); - adbd_client->on_pk_request().connect([&pk, test](const AdbdClient::PKRequest& req){ + adbd_client->on_pk_request().connect([&pk, main_thread, test](const AdbdClient::PKRequest& req){ + EXPECT_EQ(main_thread, g_thread_self()); g_message("in on_pk_request with %s", req.public_key.c_str()); pk = req.public_key; req.respond(test.response); }); - // fire up a mock ADB server with a preloaded request, and wait for a response + // start a mock AdbdServer with to fire test key requests and wait for a response auto adbd_server = std::make_shared(socket_path, std::vector{test.request}); wait_for([adbd_server](){return !adbd_server->m_responses.empty();}, 2000); EXPECT_EQ(test.expected_pk, pk); -- cgit v1.2.3