19a44a7d94
Reviewers: mferencevic Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D897
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#ifndef NDEBUG
|
|
#define NDEBUG
|
|
#endif
|
|
|
|
#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
|
|
NetworkEndpoint endpoint(interface, "0");
|
|
printf("ADDRESS: %s, PORT: %d\n", endpoint.address(), endpoint.port());
|
|
|
|
// initialize server
|
|
TestData session_data;
|
|
ServerT server(endpoint, session_data);
|
|
|
|
// start server
|
|
int N = (std::thread::hardware_concurrency() + 1) / 2;
|
|
std::thread server_thread([&] { server.Start(N); });
|
|
|
|
const auto &ep = server.endpoint();
|
|
// start clients
|
|
std::vector<std::thread> clients;
|
|
for (int i = 0; i < N; ++i)
|
|
clients.push_back(std::thread(client_run, i, interface, ep.port_str(), data,
|
|
30000, SIZE));
|
|
|
|
// cleanup clients
|
|
for (int i = 0; i < N; ++i) clients[i].join();
|
|
|
|
// stop server
|
|
server.Shutdown();
|
|
server_thread.join();
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
google::InitGoogleLogging(argv[0]);
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|