Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
inspector: wait for both sides closing
Removes race condition when test relied on both sides of the socket
to be closed on the same UV event loop iteration.

Fixes: #8498
  • Loading branch information
Eugene Ostroukhov committed Sep 13, 2016
commit e2d869ace90db443e21113cb8ad2a3dabdefe09e
14 changes: 8 additions & 6 deletions test/cctest/test_inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,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 @@ -481,8 +486,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 @@ -493,8 +497,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 @@ -508,8 +511,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