summaryrefslogtreecommitdiffhomepage
path: root/tests/test-webserver.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-09 21:17:26 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-09 21:17:26 +0100
commit1191f07767583a9b19280a4f29cb1b0bd6799785 (patch)
tree55563e05902173f9b809fcc81fce5a979253522a /tests/test-webserver.cpp
parentdc2e2b3e293a8374a2627982b521cc6865129c49 (diff)
Websocket proxy
Diffstat (limited to 'tests/test-webserver.cpp')
-rw-r--r--tests/test-webserver.cpp59
1 files changed, 34 insertions, 25 deletions
diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp
index 6bbf302..1c1e6cc 100644
--- a/tests/test-webserver.cpp
+++ b/tests/test-webserver.cpp
@@ -503,38 +503,38 @@ public:
throw std::runtime_error("Fork unsuccessful.");
if (m_pid == 0) { // child process branch
- while (true) {
- try
- {
- auto const address = boost::asio::ip::make_address("localhost");
- auto const port = static_cast<unsigned short>(9876);
+ try
+ {
+ auto const address = boost::asio::ip::make_address("::1");
+ auto const port = static_cast<unsigned short>(9876);
- // The io_context is required for all I/O
- boost::asio::io_context ioc{1};
+ // The io_context is required for all I/O
+ boost::asio::io_context ioc{1};
- // The acceptor receives incoming connections
- boost::asio::ip::tcp::acceptor acceptor{ioc, {address, port}};
- for(;;)
- {
- // This will receive the new connection
- boost::asio::ip::tcp::socket socket{ioc};
+ // The acceptor receives incoming connections
+ boost::asio::ip::tcp::acceptor acceptor{ioc, {address, port}};
+ for(;;)
+ {
+ // This will receive the new connection
+ boost::asio::ip::tcp::socket socket{ioc};
- // Block until we get a connection
- acceptor.accept(socket);
+ // Block until we get a connection
+ acceptor.accept(socket);
- // Launch the session, transferring ownership of the socket
- std::thread(
- &WebsocketServerProcess::do_session, this,
- std::move(socket)).detach();
- }
- }
- catch (const std::exception& e)
- {
- std::cerr << "Error: " << e.what() << std::endl;
+ // Launch the session, transferring ownership of the socket
+ std::thread(
+ &WebsocketServerProcess::do_session, this,
+ std::move(socket)).detach();
}
}
+ catch (const std::exception& e)
+ {
+ std::cerr << "Error: " << e.what() << std::endl;
+ }
exit(0);
}
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
void stop()
@@ -542,7 +542,7 @@ public:
if (!is_running())
throw std::runtime_error("Process not running, so it can't be stopped");
- if (kill(m_pid, SIGKILL) != 0)
+ if (kill(m_pid, SIGTERM) != 0)
throw std::runtime_error("Unable to kill process");
if (int result = waitpid(m_pid, NULL, 0); result != m_pid)
@@ -632,9 +632,18 @@ BOOST_FIXTURE_TEST_CASE(websocket, Fixture)
data = std::string(boost::asio::buffers_begin(buffer.data()), boost::asio::buffers_end(buffer.data()));
BOOST_CHECK_EQUAL(data, "request1: 1");
+
+ buffer.consume(buffer.size());
+
+ ws.write(boost::asio::buffer(std::string(text)));
+ ws.read(buffer);
+ data = std::string(boost::asio::buffers_begin(buffer.data()), boost::asio::buffers_end(buffer.data()));
+ BOOST_CHECK_EQUAL(data, "request1: 2");
+
// Close the WebSocket connection
ws.close(boost::beast::websocket::close_code::normal);
BOOST_REQUIRE(serverProcess.is_running());
+ BOOST_REQUIRE(websocketProcess.is_running());
}