forked from boostorg/beast
websocket test fixes
This commit is contained in:
@@ -886,18 +886,18 @@ read_some(
|
|||||||
static_assert(is_mutable_buffer_sequence<
|
static_assert(is_mutable_buffer_sequence<
|
||||||
MutableBufferSequence>::value,
|
MutableBufferSequence>::value,
|
||||||
"MutableBufferSequence requirements not met");
|
"MutableBufferSequence requirements not met");
|
||||||
// Make sure the stream is open
|
|
||||||
if(failed_)
|
|
||||||
{
|
|
||||||
ec = boost::asio::error::operation_aborted;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
using beast::detail::clamp;
|
using beast::detail::clamp;
|
||||||
using boost::asio::buffer;
|
using boost::asio::buffer;
|
||||||
using boost::asio::buffer_cast;
|
using boost::asio::buffer_cast;
|
||||||
using boost::asio::buffer_size;
|
using boost::asio::buffer_size;
|
||||||
close_code code{};
|
close_code code{};
|
||||||
std::size_t bytes_written = 0;
|
std::size_t bytes_written = 0;
|
||||||
|
// Make sure the stream is open
|
||||||
|
if(failed_)
|
||||||
|
{
|
||||||
|
ec = boost::asio::error::operation_aborted;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
loop:
|
loop:
|
||||||
// See if we need to read a frame header. This
|
// See if we need to read a frame header. This
|
||||||
// condition is structured to give the decompressor
|
// condition is structured to give the decompressor
|
||||||
|
@@ -115,12 +115,12 @@ enum class frame_type
|
|||||||
template<class NextLayer>
|
template<class NextLayer>
|
||||||
class stream
|
class stream
|
||||||
{
|
{
|
||||||
|
friend class close_test;
|
||||||
friend class frame_test;
|
friend class frame_test;
|
||||||
|
friend class ping_test;
|
||||||
|
friend class read_test;
|
||||||
friend class stream_test;
|
friend class stream_test;
|
||||||
friend class stream_close_test;
|
friend class write_test;
|
||||||
friend class stream_ping_test;
|
|
||||||
friend class stream_read_test;
|
|
||||||
friend class stream_write_test;
|
|
||||||
|
|
||||||
/* The read buffer has to be at least as large
|
/* The read buffer has to be at least as large
|
||||||
as the largest possible control frame including
|
as the largest possible control frame including
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_accept_test : public websocket_test_suite
|
class accept_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -579,7 +579,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_accept);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,accept);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_close_test : public websocket_test_suite
|
class close_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
w.close(ws, close_code::going_away);
|
w.close(ws, close_code::going_away);
|
||||||
});
|
});
|
||||||
|
|
||||||
// double close
|
// already closed
|
||||||
{
|
{
|
||||||
echo_server es{log};
|
echo_server es{log};
|
||||||
stream<test::stream> ws{ios_};
|
stream<test::stream> ws{ios_};
|
||||||
@@ -257,7 +257,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_close);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,close);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_handshake_test : public websocket_test_suite
|
class handshake_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -221,7 +221,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_handshake);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,handshake);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_ping_test : public websocket_test_suite
|
class ping_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -38,6 +38,46 @@ public:
|
|||||||
{
|
{
|
||||||
w.pong(ws, {});
|
w.pong(ws, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ping, already closed
|
||||||
|
{
|
||||||
|
echo_server es{log};
|
||||||
|
stream<test::stream> ws{ios_};
|
||||||
|
ws.next_layer().connect(es.stream());
|
||||||
|
ws.handshake("localhost", "/");
|
||||||
|
ws.close({});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
w.ping(ws, {});
|
||||||
|
fail("", __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
catch(system_error const& se)
|
||||||
|
{
|
||||||
|
BEAST_EXPECTS(
|
||||||
|
se.code() == boost::asio::error::operation_aborted,
|
||||||
|
se.code().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pong, already closed
|
||||||
|
{
|
||||||
|
echo_server es{log};
|
||||||
|
stream<test::stream> ws{ios_};
|
||||||
|
ws.next_layer().connect(es.stream());
|
||||||
|
ws.handshake("localhost", "/");
|
||||||
|
ws.close({});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
w.pong(ws, {});
|
||||||
|
fail("", __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
catch(system_error const& se)
|
||||||
|
{
|
||||||
|
BEAST_EXPECTS(
|
||||||
|
se.code() == boost::asio::error::operation_aborted,
|
||||||
|
se.code().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -50,54 +90,6 @@ public:
|
|||||||
doTestPing(AsyncClient{yield});
|
doTestPing(AsyncClient{yield});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ping, already closed
|
|
||||||
{
|
|
||||||
stream<test::stream> ws{ios_};
|
|
||||||
error_code ec;
|
|
||||||
ws.ping({}, ec);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
// async_ping, already closed
|
|
||||||
{
|
|
||||||
boost::asio::io_service ios;
|
|
||||||
stream<test::stream> ws{ios};
|
|
||||||
ws.async_ping({},
|
|
||||||
[&](error_code ec)
|
|
||||||
{
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
});
|
|
||||||
ios.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// pong, already closed
|
|
||||||
{
|
|
||||||
stream<test::stream> ws{ios_};
|
|
||||||
error_code ec;
|
|
||||||
ws.pong({}, ec);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
// async_pong, already closed
|
|
||||||
{
|
|
||||||
boost::asio::io_service ios;
|
|
||||||
stream<test::stream> ws{ios};
|
|
||||||
ws.async_pong({},
|
|
||||||
[&](error_code ec)
|
|
||||||
{
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
});
|
|
||||||
ios.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// suspend on write
|
// suspend on write
|
||||||
{
|
{
|
||||||
echo_server es{log};
|
echo_server es{log};
|
||||||
@@ -204,7 +196,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_ping);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,ping);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_read_test : public websocket_test_suite
|
class read_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -71,6 +71,27 @@ public:
|
|||||||
pmd.client_enable = false;
|
pmd.client_enable = false;
|
||||||
pmd.server_enable = false;
|
pmd.server_enable = false;
|
||||||
|
|
||||||
|
// already closed
|
||||||
|
{
|
||||||
|
echo_server es{log};
|
||||||
|
stream<test::stream> ws{ios_};
|
||||||
|
ws.next_layer().connect(es.stream());
|
||||||
|
ws.handshake("localhost", "/");
|
||||||
|
ws.close({});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
multi_buffer b;
|
||||||
|
w.read(ws, b);
|
||||||
|
fail("", __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
catch(system_error const& se)
|
||||||
|
{
|
||||||
|
BEAST_EXPECTS(
|
||||||
|
se.code() == boost::asio::error::operation_aborted,
|
||||||
|
se.code().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// empty, fragmented message
|
// empty, fragmented message
|
||||||
doTest(pmd, [&](ws_type& ws)
|
doTest(pmd, [&](ws_type& ws)
|
||||||
{
|
{
|
||||||
@@ -589,7 +610,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_read);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,read);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -16,7 +16,7 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace websocket {
|
namespace websocket {
|
||||||
|
|
||||||
class stream_write_test : public websocket_test_suite
|
class write_test : public websocket_test_suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class Wrap>
|
template<class Wrap>
|
||||||
@@ -29,6 +29,26 @@ public:
|
|||||||
pmd.client_enable = false;
|
pmd.client_enable = false;
|
||||||
pmd.server_enable = false;
|
pmd.server_enable = false;
|
||||||
|
|
||||||
|
// already closed
|
||||||
|
{
|
||||||
|
echo_server es{log};
|
||||||
|
stream<test::stream> ws{ios_};
|
||||||
|
ws.next_layer().connect(es.stream());
|
||||||
|
ws.handshake("localhost", "/");
|
||||||
|
ws.close({});
|
||||||
|
try
|
||||||
|
{
|
||||||
|
w.write(ws, sbuf(""));
|
||||||
|
fail("", __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
catch(system_error const& se)
|
||||||
|
{
|
||||||
|
BEAST_EXPECTS(
|
||||||
|
se.code() == boost::asio::error::operation_aborted,
|
||||||
|
se.code().message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// message
|
// message
|
||||||
doTest(pmd, [&](ws_type& ws)
|
doTest(pmd, [&](ws_type& ws)
|
||||||
{
|
{
|
||||||
@@ -211,30 +231,6 @@ public:
|
|||||||
doTestWrite(AsyncClient{yield});
|
doTestWrite(AsyncClient{yield});
|
||||||
});
|
});
|
||||||
|
|
||||||
// already closed
|
|
||||||
{
|
|
||||||
stream<test::stream> ws{ios_};
|
|
||||||
error_code ec;
|
|
||||||
ws.write(sbuf(""), ec);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
// async, already closed
|
|
||||||
{
|
|
||||||
boost::asio::io_service ios;
|
|
||||||
stream<test::stream> ws{ios};
|
|
||||||
ws.async_write(sbuf(""),
|
|
||||||
[&](error_code ec)
|
|
||||||
{
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
ec == boost::asio::error::operation_aborted,
|
|
||||||
ec.message());
|
|
||||||
});
|
|
||||||
ios.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
// suspend on write
|
// suspend on write
|
||||||
{
|
{
|
||||||
echo_server es{log};
|
echo_server es{log};
|
||||||
@@ -550,7 +546,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_write);
|
BEAST_DEFINE_TESTSUITE(beast,websocket,write);
|
||||||
|
|
||||||
} // websocket
|
} // websocket
|
||||||
} // beast
|
} // beast
|
||||||
|
Reference in New Issue
Block a user