2017-03-10 22:07:42 +08:00
|
|
|
#ifndef NDEBUG
|
2017-03-06 20:37:51 +08:00
|
|
|
#define NDEBUG
|
2017-03-10 22:07:42 +08:00
|
|
|
#endif
|
2017-03-06 20:37:51 +08:00
|
|
|
|
2018-01-15 21:03:07 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-03-06 20:37:51 +08:00
|
|
|
#include "network_common.hpp"
|
|
|
|
|
|
|
|
static constexpr const char interface[] = "127.0.0.1";
|
|
|
|
|
|
|
|
unsigned char data[SIZE];
|
|
|
|
|
|
|
|
TEST(Network, Server) {
|
|
|
|
// initialize test data
|
|
|
|
initialize_data(data, SIZE);
|
|
|
|
|
|
|
|
// initialize listen socket
|
2018-01-15 21:03:07 +08:00
|
|
|
Endpoint endpoint(interface, 0);
|
|
|
|
std::cout << endpoint << std::endl;
|
2017-04-07 23:09:49 +08:00
|
|
|
|
2017-03-06 20:37:51 +08:00
|
|
|
// initialize server
|
2017-08-03 21:26:48 +08:00
|
|
|
TestData session_data;
|
2017-04-07 23:09:49 +08:00
|
|
|
int N = (std::thread::hardware_concurrency() + 1) / 2;
|
2018-06-20 23:44:47 +08:00
|
|
|
ContextT context;
|
2018-09-03 21:29:06 +08:00
|
|
|
ServerT server(endpoint, &session_data, &context, -1, "Test", N);
|
2018-10-16 16:58:41 +08:00
|
|
|
ASSERT_TRUE(server.Start());
|
2017-03-06 20:37:51 +08:00
|
|
|
|
2017-10-17 20:05:08 +08:00
|
|
|
const auto &ep = server.endpoint();
|
2017-03-06 20:37:51 +08:00
|
|
|
// start clients
|
|
|
|
std::vector<std::thread> clients;
|
2021-02-18 22:32:43 +08:00
|
|
|
for (int i = 0; i < N; ++i) clients.push_back(std::thread(client_run, i, interface, ep.port, data, 30000, SIZE));
|
2017-03-06 20:37:51 +08:00
|
|
|
|
|
|
|
// cleanup clients
|
|
|
|
for (int i = 0; i < N; ++i) clients[i].join();
|
2018-09-27 21:07:46 +08:00
|
|
|
|
|
|
|
// shutdown server
|
|
|
|
server.Shutdown();
|
|
|
|
server.AwaitShutdown();
|
2017-03-06 20:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|