2022-03-31 19:52:43 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
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
|
|
|
|
|
|
|
#include <chrono>
|
2018-01-15 21:03:07 +08:00
|
|
|
#include <iostream>
|
2017-03-06 20:37:51 +08:00
|
|
|
|
|
|
|
#include "network_common.hpp"
|
|
|
|
|
2022-03-31 19:52:43 +08:00
|
|
|
inline constexpr const char interface[] = "127.0.0.1";
|
2017-03-06 20:37:51 +08:00
|
|
|
|
|
|
|
unsigned char data[SIZE];
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
TEST(Network, SessionLeak) {
|
|
|
|
// initialize test data
|
|
|
|
initialize_data(data, SIZE);
|
|
|
|
|
|
|
|
// initialize listen socket
|
2018-01-15 21:03:07 +08:00
|
|
|
Endpoint endpoint(interface, 0);
|
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;
|
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", 2);
|
2018-10-16 16:58:41 +08:00
|
|
|
ASSERT_TRUE(server.Start());
|
2017-03-06 20:37:51 +08:00
|
|
|
|
|
|
|
// start clients
|
|
|
|
int N = 50;
|
|
|
|
std::vector<std::thread> clients;
|
|
|
|
|
2017-10-17 20:05:08 +08:00
|
|
|
const auto &ep = server.endpoint();
|
2017-03-06 20:37:51 +08:00
|
|
|
int testlen = 3000;
|
|
|
|
for (int i = 0; i < N; ++i) {
|
2021-02-18 22:32:43 +08:00
|
|
|
clients.push_back(std::thread(client_run, i, interface, ep.port, data, testlen, testlen));
|
2017-03-06 20:37:51 +08:00
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup clients
|
|
|
|
for (int i = 0; i < N; ++i) clients[i].join();
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(2s);
|
2018-09-27 21:07:46 +08:00
|
|
|
|
|
|
|
// shutdown server
|
|
|
|
server.Shutdown();
|
|
|
|
server.AwaitShutdown();
|
2017-03-06 20:37:51 +08:00
|
|
|
}
|
|
|
|
|
2017-03-10 22:07:42 +08:00
|
|
|
// run with "valgrind --leak-check=full ./network_session_leak" to check for
|
|
|
|
// memory leaks
|
2017-03-06 20:37:51 +08:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|