Skip to content

Commit bab1c6a

Browse files
author
me
committed
more unit tests - there is a bug - need to fix
1 parent 730d776 commit bab1c6a

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

examples/unit_tests/async.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,67 @@ TEST_SUITE("[ASYNC]")
344344
}
345345
}
346346

347+
SUBCASE("async - server sends")
348+
{
349+
try
350+
{
351+
acceptor.async_accept(peer, [&](boost::system::error_code ec) {
352+
REQUIRE(!bool(ec));
353+
http::async_http_read(peer, req, buf, [&](boost::system::error_code ec, size_t) {
354+
REQUIRE(!bool(ec));
355+
REQUIRE(req.is_websocket_req());
356+
http::async_ws_accept(peer, req, [&](boost::system::error_code ec, std::size_t) {
357+
REQUIRE(!bool(ec));
358+
data_peer.assign(begin(data), end(data));
359+
http::async_ws_write(peer, data_peer, false, true, [&](boost::system::error_code ec, std::size_t nwritten) {
360+
REQUIRE(!bool(ec));
361+
printf("Written %zu bytes\n", nwritten);
362+
data_peer.assign(begin(text), end(text));
363+
http::async_ws_write(peer, data_peer, true, true, [&](boost::system::error_code ec, std::size_t) {
364+
REQUIRE(!bool(ec));
365+
http::async_ws_close(peer, http::ws_going_away, true, [&](boost::system::error_code ec) {
366+
REQUIRE(!bool(ec));
367+
});
368+
});
369+
});
370+
});
371+
});
372+
});
373+
374+
resolver.async_resolve("localhost", "6667", [&](boost::system::error_code ec, const auto& endpoints) {
375+
REQUIRE(!bool(ec));
376+
boost::asio::async_connect(client, endpoints, [&](boost::system::error_code ec, auto endpoint) {
377+
REQUIRE(!bool(ec));
378+
http::async_ws_handshake(client, "localhost", "/ws", [&](boost::system::error_code ec) {
379+
REQUIRE(!bool(ec));
380+
http::async_ws_read(client, data_client, false, [&](boost::system::error_code ec, bool is_text) {
381+
printf("%s\n", ec.message().c_str());
382+
REQUIRE(!bool(ec));
383+
REQUIRE(!is_text);
384+
REQUIRE(data_client.size() == data.size());
385+
REQUIRE(std::equal(begin(data_client), end(data_client), begin(data)));
386+
http::async_ws_read(client, data_client, false, [&](boost::system::error_code ec, bool is_text) {
387+
REQUIRE(!bool(ec));
388+
REQUIRE(is_text);
389+
REQUIRE(data_client.size() == text.size());
390+
REQUIRE(std::equal(begin(data_client), end(data_client), begin(text)));
391+
http::async_ws_read(client, data_client, false, [&](boost::system::error_code ec, bool is_text) {
392+
REQUIRE(ec == http::ws_going_away);
393+
});
394+
});
395+
});
396+
});
397+
});
398+
});
399+
400+
ioc.run();
401+
}
402+
catch(const std::exception& e)
403+
{
404+
exception_thrown = true;
405+
}
406+
}
407+
347408
REQUIRE(!exception_thrown);
348409
}
349410
}

src/http_async.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ namespace http
505505

506506
async_ws_handshake_impl (
507507
AsyncStream& sock_,
508-
std::string_view uri_,
509-
std::string_view host_
508+
std::string_view host_,
509+
std::string_view uri_
510510
) : sock{sock_},
511511
uri{uri_},
512512
host{host_}

0 commit comments

Comments
 (0)