Skip to content

Commit a67f11d

Browse files
author
Eugene Ostroukhov
committed
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: nodejs#8498 PR-URL: nodejs#8505 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-by: Fedor Indutny <[email protected]>
1 parent 078bf68 commit a67f11d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/cctest/test_inspector_socket.cc

+8-6
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ static void manual_inspector_socket_cleanup() {
330330
inspector.buffer.clear();
331331
}
332332

333+
static void assert_both_sockets_closed() {
334+
SPIN_WHILE(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)));
335+
SPIN_WHILE(uv_is_active(reinterpret_cast<uv_handle_t*>(&inspector.client)));
336+
}
337+
333338
static void on_connection(uv_connect_t* connect, int status) {
334339
GTEST_ASSERT_EQ(0, status);
335340
connect->data = connect;
@@ -503,8 +508,7 @@ TEST_F(InspectorSocketTest, ExtraTextBeforeRequest) {
503508
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
504509
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
505510
expect_handshake_failure();
506-
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
507-
EXPECT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&socket)), 0);
511+
assert_both_sockets_closed();
508512
}
509513

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

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

537539
TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) {

0 commit comments

Comments
 (0)