diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2016-04-23 12:29:45 +0200 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2016-04-23 12:29:45 +0200 |
commit | 0f5534d22903f73e2d33ea2e29efb2307463bfa4 (patch) | |
tree | cfcebfaf499a8d5ec58e80155a0e0ea4bce984c5 /tests/utils | |
parent | ce5234162fa0c534ff9abf3fce3d03f4b01e893e (diff) | |
download | ayatana-indicator-display-0f5534d22903f73e2d33ea2e29efb2307463bfa4.tar.gz ayatana-indicator-display-0f5534d22903f73e2d33ea2e29efb2307463bfa4.tar.bz2 ayatana-indicator-display-0f5534d22903f73e2d33ea2e29efb2307463bfa4.zip |
in tests/utils/adbd-server.h, fix a timing bug in the test scaffolding by creating the adb socket in AdbdServer's ctor instead of in its worker thread.
Diffstat (limited to 'tests/utils')
-rw-r--r-- | tests/utils/adbd-server.h | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/tests/utils/adbd-server.h b/tests/utils/adbd-server.h index b574622..585380f 100644 --- a/tests/utils/adbd-server.h +++ b/tests/utils/adbd-server.h @@ -38,7 +38,7 @@ public: GAdbdServer(const std::string& socket_path, const std::vector<std::string>& requests): m_requests{requests}, - m_socket_path{socket_path}, + m_server_socket{create_server_socket(socket_path)}, m_cancellable{g_cancellable_new()}, m_worker_thread{&GAdbdServer::worker_func, this} { @@ -50,6 +50,7 @@ public: g_cancellable_cancel(m_cancellable); m_worker_thread.join(); g_clear_object(&m_cancellable); + g_clear_object(&m_server_socket); } const std::vector<std::string> m_requests; @@ -59,18 +60,14 @@ private: void worker_func() // runs in worker thread { - auto server_socket = create_server_socket(m_socket_path); auto requests = m_requests; - GError* error {}; - g_socket_listen (server_socket, &error); - g_assert_no_error (error); - while (!g_cancellable_is_cancelled(m_cancellable) && !requests.empty()) { // wait for a client connection g_message("GAdbdServer::Impl::worker_func() calling g_socket_accept()"); - auto client_socket = g_socket_accept(server_socket, m_cancellable, &error); + GError* error {}; + auto client_socket = g_socket_accept(m_server_socket, m_cancellable, &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_message("GAdbdServer: Error accepting socket connection: %s", error->message); @@ -121,8 +118,6 @@ private: // cleanup g_clear_object(&client_socket); } - - g_clear_object(&server_socket); } // bind to a local domain socket @@ -139,11 +134,14 @@ private: g_assert_no_error (error); g_clear_object (&address); + g_socket_listen (socket, &error); + g_assert_no_error (error); + return socket; } - const std::string m_socket_path; - GCancellable* m_cancellable = nullptr; + GSocket* m_server_socket {}; + GCancellable* m_cancellable {}; std::thread m_worker_thread; }; |