@@ -35,6 +35,8 @@ static std::string last_path; // NOLINT(runtime/string)
3535static void (*handshake_delegate)(enum inspector_handshake_event state,
3636 const std::string& path,
3737 bool * should_continue);
38+ static const char SERVER_CLOSE_FRAME[] = {' \x88 ' , ' \x00 ' };
39+
3840
3941struct read_expects {
4042 const char * expected;
@@ -879,7 +881,6 @@ TEST_F(InspectorSocketTest, Send1Mb) {
879881 // 3. Close
880882 const char CLIENT_CLOSE_FRAME[] = {' \x88 ' , ' \x80 ' , ' \x2D ' ,
881883 ' \x0E ' , ' \x1E ' , ' \xFA ' };
882- const char SERVER_CLOSE_FRAME[] = {' \x88 ' , ' \x00 ' };
883884 do_write (CLIENT_CLOSE_FRAME, sizeof (CLIENT_CLOSE_FRAME));
884885 expect_on_client (SERVER_CLOSE_FRAME, sizeof (SERVER_CLOSE_FRAME));
885886 GTEST_ASSERT_EQ (0 , uv_is_active (
@@ -906,4 +907,33 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
906907 EXPECT_EQ (UV_EPROTO, err);
907908}
908909
910+ static void ServerClosedByClient_cb (InspectorSocket* socket, int code) {
911+ *static_cast <bool *>(socket->data ) = true ;
912+ }
913+
914+ TEST_F (InspectorSocketTest, NoCloseResponseFromClinet) {
915+ ASSERT_TRUE (connected);
916+ ASSERT_FALSE (inspector_ready);
917+ do_write (const_cast <char *>(HANDSHAKE_REQ), sizeof (HANDSHAKE_REQ) - 1 );
918+ SPIN_WHILE (!inspector_ready);
919+ expect_handshake ();
920+
921+ // 2. Brief exchange
922+ const char SERVER_MESSAGE[] = " abcd" ;
923+ const char CLIENT_FRAME[] = {' \x81 ' , ' \x04 ' , ' a' , ' b' , ' c' , ' d' };
924+ inspector_write (&inspector, SERVER_MESSAGE, sizeof (SERVER_MESSAGE) - 1 );
925+ expect_on_client (CLIENT_FRAME, sizeof (CLIENT_FRAME));
926+
927+ bool closed = false ;
928+
929+ inspector.data = &closed;
930+ inspector_close (&inspector, ServerClosedByClient_cb);
931+ expect_on_client (SERVER_CLOSE_FRAME, sizeof (SERVER_CLOSE_FRAME));
932+ uv_close (reinterpret_cast <uv_handle_t *>(&client_socket), nullptr );
933+ SPIN_WHILE (!closed);
934+ inspector.data = nullptr ;
935+ GTEST_ASSERT_EQ (0 , uv_is_active (
936+ reinterpret_cast <uv_handle_t *>(&client_socket)));
937+ }
938+
909939} // anonymous namespace
0 commit comments