Add flaky test

This commit is contained in:
Andi Skrgat 2024-03-20 10:31:32 +01:00
parent 03f5cc2f33
commit 5d5c39f862
3 changed files with 25 additions and 18 deletions

View File

@ -28,10 +28,9 @@ namespace memgraph::coordination {
using nuraft::ptr;
CoordinatorInstance::CoordinatorInstance(CoordinatorInstanceInitConfig const &config)
CoordinatorInstance::CoordinatorInstance()
: thread_pool_{1},
raft_state_(RaftState::MakeRaftState(
config,
[this]() {
spdlog::info("Leader changed, starting all replication instances!");
auto const instances = raft_state_.GetReplicationInstances();

View File

@ -76,6 +76,7 @@ class CoordinatorInstance {
void ReplicaFailCallback(std::string_view);
HealthCheckClientCallback client_succ_cb_, client_fail_cb_;
// NOTE: Must be std::list because we rely on pointer stability.
// TODO: (andi) Rename + virtualize for mocking.
std::list<ReplicationInstanceConnector> repl_instances_;

View File

@ -46,21 +46,33 @@ class CoordinatorInstanceTest : public ::testing::Test {
"MG_tests_unit_coordinator_instance"};
};
TEST_F(CoordinatorInstanceTest, ShowInstancesEmptyTest) {
auto const init_config =
CoordinatorInstanceInitConfig{.coordinator_id = 4, .coordinator_port = 10110, .bolt_port = 7686};
// TEST_F(CoordinatorInstanceTest, ShowInstancesEmptyTest) {
// auto const init_config =
// CoordinatorInstanceInitConfig{.coordinator_id = 4, .coordinator_port = 10110, .bolt_port = 7686};
//
// auto const instance1 = CoordinatorInstance{init_config};
// auto const instances = instance1.ShowInstances();
// ASSERT_EQ(instances.size(), 1);
// ASSERT_EQ(instances[0].instance_name, "coordinator_4");
// ASSERT_EQ(instances[0].health, "unknown");
// ASSERT_EQ(instances[0].raft_socket_address, "127.0.0.1:10110");
// ASSERT_EQ(instances[0].coord_socket_address, "");
// ASSERT_EQ(instances[0].cluster_role, "coordinator");
// }
auto const instance1 = CoordinatorInstance{init_config};
auto const instances = instance1.ShowInstances();
ASSERT_EQ(instances.size(), 1);
ASSERT_EQ(instances[0].instance_name, "coordinator_4");
ASSERT_EQ(instances[0].health, "unknown");
ASSERT_EQ(instances[0].raft_socket_address, "127.0.0.1:10110");
ASSERT_EQ(instances[0].coord_socket_address, "");
ASSERT_EQ(instances[0].cluster_role, "coordinator");
int KillCode() {
int *arr = new int[100];
delete[] arr;
return arr[0];
}
TEST_F(CoordinatorInstanceTest, ConnectCoordinators) {
int b = KillCode();
auto const init_config1 =
CoordinatorInstanceInitConfig{.coordinator_id = 1, .coordinator_port = 10111, .bolt_port = 7687};
auto instance1 = CoordinatorInstance{init_config1};
auto const init_config2 =
CoordinatorInstanceInitConfig{.coordinator_id = 2, .coordinator_port = 10112, .bolt_port = 7688};
@ -71,11 +83,6 @@ TEST_F(CoordinatorInstanceTest, ConnectCoordinators) {
auto const instance3 = CoordinatorInstance{init_config3};
auto const init_config1 =
CoordinatorInstanceInitConfig{.coordinator_id = 1, .coordinator_port = 10111, .bolt_port = 7687};
auto instance1 = CoordinatorInstance{init_config1};
instance1.AddCoordinatorInstance(CoordinatorToCoordinatorConfig{.coordinator_id = 2,
.bolt_server = Endpoint{"127.0.0.1", 7688},
.coordinator_server = Endpoint{"127.0.0.1", 10112}});