53c405c699
Summary: This diff changes the RPC layer to directly return `TResponse` to the user when issuing a `Call<...>` RPC call. The call throws an exception on failure (instead of the previous return `nullopt`). All servers (network, RPC and distributed) are set to have explicit `Shutdown` methods so that a controlled shutdown can always be performed. The object destructors now have `CHECK`s to enforce that the `AwaitShutdown` methods were called. The distributed memgraph is changed that none of the binaries (master/workers) crash when there is a communication failure. Instead, the whole cluster starts a graceful shutdown when a persistent communication error is detected. Transient errors are allowed during execution. The transaction that errored out will be aborted on the whole cluster. The cluster state is managed using a new Heartbeat RPC call. Reviewers: buda, teon.banek, msantl Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1604
42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#include <chrono>
|
|
#include <memory>
|
|
#include <unordered_set>
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "utils/future.hpp"
|
|
#include "utils/thread.hpp"
|
|
#include "utils/timer.hpp"
|
|
|
|
TEST(ThreadPool, RunMany) {
|
|
utils::ThreadPool tp(10, "Test");
|
|
const int kResults = 10000;
|
|
std::vector<utils::Future<int>> results;
|
|
for (int i = 0; i < kResults; ++i) {
|
|
results.emplace_back(tp.Run([i]() { return i; }));
|
|
}
|
|
|
|
std::unordered_set<int> result_set;
|
|
for (auto &result : results) result_set.insert(result.get());
|
|
EXPECT_EQ(result_set.size(), kResults);
|
|
}
|
|
|
|
TEST(ThreadPool, EnsureParallel) {
|
|
using namespace std::chrono_literals;
|
|
|
|
const int kSize = 10;
|
|
utils::ThreadPool tp(kSize, "Test");
|
|
std::vector<utils::Future<void>> results;
|
|
|
|
utils::Timer t;
|
|
for (int i = 0; i < kSize; ++i) {
|
|
results.emplace_back(tp.Run([]() { std::this_thread::sleep_for(50ms); }));
|
|
}
|
|
for (auto &res : results) res.wait();
|
|
|
|
auto elapsed = t.Elapsed();
|
|
EXPECT_GE(elapsed, 30ms);
|
|
EXPECT_LE(elapsed, 200ms);
|
|
}
|