From f817875235aec724ba1c7130d7dfebb046b99da2 Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Mon, 12 Sep 2016 14:49:07 -0700 Subject: [PATCH] inspector: wait for both sides closing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes race condition when test relied on both sides of the socket to be closed on the same UV event loop iteration. Fixes: nodejs/node#8498 PR-URL: https://github.com/nodejs/node/pull/8505 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: James M Snell Reviewed-by: Fedor Indutny --- test/cctest/test_inspector_socket.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/cctest/test_inspector_socket.cc b/test/cctest/test_inspector_socket.cc index f45593584a..3b927bdc2c 100644 --- a/test/cctest/test_inspector_socket.cc +++ b/test/cctest/test_inspector_socket.cc @@ -330,6 +330,11 @@ static void manual_inspector_socket_cleanup() { inspector.buffer.clear(); } +static void assert_both_sockets_closed() { + SPIN_WHILE(uv_is_active(reinterpret_cast(&client_socket))); + SPIN_WHILE(uv_is_active(reinterpret_cast(&inspector.client))); +} + static void on_connection(uv_connect_t* connect, int status) { GTEST_ASSERT_EQ(0, status); connect->data = connect; @@ -503,8 +508,7 @@ TEST_F(InspectorSocketTest, ExtraTextBeforeRequest) { do_write(const_cast(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1); SPIN_WHILE(last_event != kInspectorHandshakeFailed); expect_handshake_failure(); - EXPECT_EQ(uv_is_active(reinterpret_cast(&client_socket)), 0); - EXPECT_EQ(uv_is_active(reinterpret_cast(&socket)), 0); + assert_both_sockets_closed(); } TEST_F(InspectorSocketTest, ExtraLettersBeforeRequest) { @@ -515,8 +519,7 @@ TEST_F(InspectorSocketTest, ExtraLettersBeforeRequest) { do_write(const_cast(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1); SPIN_WHILE(last_event != kInspectorHandshakeFailed); expect_handshake_failure(); - EXPECT_EQ(uv_is_active(reinterpret_cast(&client_socket)), 0); - EXPECT_EQ(uv_is_active(reinterpret_cast(&socket)), 0); + assert_both_sockets_closed(); } TEST_F(InspectorSocketTest, RequestWithoutKey) { @@ -530,8 +533,7 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) { do_write(const_cast(BROKEN_REQUEST), sizeof(BROKEN_REQUEST) - 1); SPIN_WHILE(last_event != kInspectorHandshakeFailed); expect_handshake_failure(); - EXPECT_EQ(uv_is_active(reinterpret_cast(&client_socket)), 0); - EXPECT_EQ(uv_is_active(reinterpret_cast(&socket)), 0); + assert_both_sockets_closed(); } TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) {