Skip to content

Commit

Permalink
inspector: wait for both sides closing
Browse files Browse the repository at this point in the history
Removes race condition when test relied on both sides of the socket
to be closed on the same UV event loop iteration.

Fixes: #8498
PR-URL: #8505
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
Eugene Ostroukhov authored and Myles Borins committed Sep 30, 2016
1 parent 4ed46b4 commit f817875
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/cctest/test_inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uv_handle_t*>(&client_socket)));
SPIN_WHILE(uv_is_active(reinterpret_cast<uv_handle_t*>(&inspector.client)));
}

static void on_connection(uv_connect_t* connect, int status) {
GTEST_ASSERT_EQ(0, status);
connect->data = connect;
Expand Down Expand Up @@ -503,8 +508,7 @@ TEST_F(InspectorSocketTest, ExtraTextBeforeRequest) {
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
expect_handshake_failure();
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&socket)), 0);
assert_both_sockets_closed();
}

TEST_F(InspectorSocketTest, ExtraLettersBeforeRequest) {
Expand All @@ -515,8 +519,7 @@ TEST_F(InspectorSocketTest, ExtraLettersBeforeRequest) {
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
expect_handshake_failure();
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&socket)), 0);
assert_both_sockets_closed();
}

TEST_F(InspectorSocketTest, RequestWithoutKey) {
Expand All @@ -530,8 +533,7 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) {
do_write(const_cast<char*>(BROKEN_REQUEST), sizeof(BROKEN_REQUEST) - 1);
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
expect_handshake_failure();
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&socket)), 0);
assert_both_sockets_closed();
}

TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) {
Expand Down

0 comments on commit f817875

Please sign in to comment.