From eaecca3e347adac7a097f3ea0fcfe8dd5d5d357a Mon Sep 17 00:00:00 2001 From: heyuchen Date: Sat, 10 Oct 2020 14:03:38 +0800 Subject: [PATCH] refactor: refactor replica split unit tests --- src/replica/split/test/replica_split_test.cpp | 473 +++++++++--------- 1 file changed, 225 insertions(+), 248 deletions(-) diff --git a/src/replica/split/test/replica_split_test.cpp b/src/replica/split/test/replica_split_test.cpp index 387f9020fa..2dc8f31682 100644 --- a/src/replica/split/test/replica_split_test.cpp +++ b/src/replica/split/test/replica_split_test.cpp @@ -24,76 +24,101 @@ namespace dsn { namespace replication { -class replica_split_test : public testing::Test +class replica_split_test : public replica_test_base { public: - void SetUp() + replica_split_test() { - _stub = make_unique(); - _stub->set_state_connected(); mock_app_info(); - _parent_replica = _stub->generate_replica( - _app_info, _parent_pid, partition_status::PS_PRIMARY, _init_ballot); + _parent_replica = stub->generate_replica( + _app_info, PARENT_GPID, partition_status::PS_PRIMARY, INIT_BALLOT); _parent_split_mgr = make_unique(_parent_replica.get()); - mock_group_check_request(); + fail::setup(); + fail::cfg("replica_update_local_configuration", "return()"); } - void TearDown() {} + ~replica_split_test() { fail::teardown(); } + + /// mock functions void mock_app_info() { - _app_info.app_id = 2; - _app_info.app_name = "split_test"; + _app_info.app_id = APP_ID; + _app_info.app_name = APP_NAME; _app_info.app_type = "replica"; _app_info.is_stateful = true; _app_info.max_replica_count = 3; - _app_info.partition_count = 8; - } - - void mock_group_check_request() - { - _group_check_req.child_gpid = _child_pid; - _group_check_req.config.ballot = _init_ballot; - _group_check_req.config.status = partition_status::PS_PRIMARY; - } - - void mock_notify_catch_up_request() - { - _parent_split_mgr->_child_gpid = _child_pid; - _catch_up_req.child_gpid = _child_pid; - _catch_up_req.parent_gpid = _parent_pid; - _catch_up_req.child_ballot = _init_ballot; - _catch_up_req.child_address = dsn::rpc_address("127.0.0.1", 1); + _app_info.partition_count = OLD_PARTITION_COUNT; } + // TODO(heyuchen): refactor it void mock_register_child_request() { partition_configuration &p_config = _register_req.parent_config; - p_config.pid = _parent_pid; - p_config.ballot = _init_ballot; - p_config.last_committed_decree = _decree; + p_config.pid = PARENT_GPID; + p_config.ballot = INIT_BALLOT; + p_config.last_committed_decree = DECREE; partition_configuration &c_config = _register_req.child_config; - c_config.pid = _child_pid; - c_config.ballot = _init_ballot + 1; + c_config.pid = CHILD_GPID; + c_config.ballot = INIT_BALLOT + 1; c_config.last_committed_decree = 0; _register_req.app = _app_info; _register_req.primary_address = dsn::rpc_address("127.0.0.1", 10086); } - void generate_child(partition_status::type status) + void generate_child() { - _child_replica = _stub->generate_replica(_app_info, _child_pid, status, _init_ballot); + _child_replica = stub->generate_replica( + _app_info, CHILD_GPID, partition_status::PS_PARTITION_SPLIT, INIT_BALLOT); _child_split_mgr = make_unique(_child_replica.get()); - _parent_split_mgr->_child_gpid = _child_pid; - _parent_split_mgr->_child_init_ballot = _init_ballot; + } + + void generate_child(bool is_prepare_list_copied, bool is_caught_up) + { + generate_child(); + _child_replica->_split_states.parent_gpid = PARENT_GPID; + _child_replica->_split_states.is_prepare_list_copied = is_prepare_list_copied; + _child_replica->_split_states.is_caught_up = is_caught_up; + } + + void mock_child_split_context(bool is_prepare_list_copied, bool is_caught_up) + { + _child_replica->set_partition_status(partition_status::PS_PARTITION_SPLIT); + _child_replica->_split_states.parent_gpid = PARENT_GPID; + _child_replica->_split_states.is_prepare_list_copied = is_prepare_list_copied; + _child_replica->_split_states.is_caught_up = is_caught_up; + } + + void mock_parent_split_context(partition_status::type status) + { + _parent_split_mgr->_child_gpid = CHILD_GPID; + _parent_split_mgr->_child_init_ballot = INIT_BALLOT; + _parent_replica->set_partition_status(status); + } + + void mock_primary_parent_split_context(bool sync_send_write_request, + bool will_all_caught_up = false) + { + mock_parent_split_context(partition_status::PS_PRIMARY); + _parent_replica->_primary_states.statuses.clear(); + _parent_replica->_primary_states.statuses[PRIMARY] = partition_status::PS_PRIMARY; + _parent_replica->_primary_states.statuses[SECONDARY] = partition_status::PS_SECONDARY; + _parent_replica->_primary_states.statuses[SECONDARY2] = partition_status::PS_SECONDARY; + _parent_replica->_primary_states.sync_send_write_request = sync_send_write_request; + if (!sync_send_write_request) { + _parent_replica->_primary_states.caught_up_children.insert(SECONDARY); + if (will_all_caught_up) { + _parent_replica->_primary_states.caught_up_children.insert(SECONDARY2); + } + } } void mock_shared_log() { mock_mutation_log_shared_ptr shared_log_mock = new mock_mutation_log_shared("./"); - _stub->set_log(shared_log_mock); + stub->set_log(shared_log_mock); } void mock_private_log(gpid pid, mock_replica_ptr rep, bool mock_log_file_flag) @@ -109,11 +134,11 @@ class replica_split_test : public testing::Test void mock_prepare_list(mock_replica_ptr rep, bool add_to_plog) { - _mock_plist = new prepare_list(rep, 1, _max_count, [](mutation_ptr mu) {}); - for (int i = 1; i < _max_count + 1; ++i) { + _mock_plist = new prepare_list(rep, 1, MAX_COUNT, [](mutation_ptr mu) {}); + for (int i = 1; i < MAX_COUNT + 1; ++i) { mutation_ptr mu = new mutation(); mu->data.header.decree = i; - mu->data.header.ballot = _init_ballot; + mu->data.header.ballot = INIT_BALLOT; _mock_plist->put(mu); if (add_to_plog) { rep->_private_log->append(mu, LPC_WRITE_REPLICATION_LOG_PRIVATE, nullptr, nullptr); @@ -126,21 +151,14 @@ class replica_split_test : public testing::Test void mock_parent_states() { mock_shared_log(); - mock_private_log(_parent_pid, _parent_replica, true); + mock_private_log(PARENT_GPID, _parent_replica, true); mock_prepare_list(_parent_replica, true); } - void mock_child_split_context(gpid parent_gpid, bool is_prepare_list_copied, bool is_caught_up) - { - _child_replica->_split_states.parent_gpid = parent_gpid; - _child_replica->_split_states.is_prepare_list_copied = is_prepare_list_copied; - _child_replica->_split_states.is_caught_up = is_caught_up; - } - void mock_mutation_list(decree min_decree) { // mock mutation list - for (int d = 1; d < _max_count; ++d) { + for (int d = 1; d < MAX_COUNT; ++d) { mutation_ptr mu = _mock_plist->get_mutation_by_decree(d); if (d > min_decree) { _mutation_list.push_back(mu); @@ -148,36 +166,14 @@ class replica_split_test : public testing::Test } } - void mock_parent_primary_context(bool will_all_caught_up) - { - _parent_replica->_primary_states.statuses[dsn::rpc_address("127.0.0.1", 1)] = - partition_status::PS_PRIMARY; - _parent_replica->_primary_states.statuses[dsn::rpc_address("127.0.0.1", 2)] = - partition_status::PS_SECONDARY; - _parent_replica->_primary_states.statuses[dsn::rpc_address("127.0.0.1", 3)] = - partition_status::PS_SECONDARY; - _parent_replica->_primary_states.caught_up_children.insert( - dsn::rpc_address("127.0.0.1", 2)); - if (will_all_caught_up) { - _parent_replica->_primary_states.caught_up_children.insert( - dsn::rpc_address("127.0.0.1", 3)); - } - _parent_replica->_primary_states.sync_send_write_request = false; - } - - bool get_sync_send_write_request() - { - return _parent_replica->_primary_states.sync_send_write_request; - } - void mock_child_async_learn_states(mock_replica_ptr plist_rep, bool add_to_plog, decree min_decree) { mock_shared_log(); - mock_private_log(_child_pid, _child_replica, false); + mock_private_log(CHILD_GPID, _child_replica, false); mock_prepare_list(plist_rep, add_to_plog); // mock_learn_state - _mock_learn_state.to_decree_included = _decree; + _mock_learn_state.to_decree_included = DECREE; _mock_learn_state.files.push_back("fake_file_name"); // mock parent private log files _private_log_files.push_back("log.1.0.txt"); @@ -185,49 +181,44 @@ class replica_split_test : public testing::Test mock_mutation_list(min_decree); } - void cleanup_prepare_list(mock_replica_ptr rep) { rep->_prepare_list->reset(0); } + /// test functions - void cleanup_child_split_context() + void test_on_add_child(ballot b, gpid req_child_gpid) { - _child_replica->_split_states.cleanup(true); - _child_replica->tracker()->wait_outstanding_tasks(); - } - - partition_split_context get_split_context() { return _child_replica->_split_states; } + group_check_request req; + req.config.ballot = b; + req.config.status = partition_status::PS_PRIMARY; + req.__set_child_gpid(req_child_gpid); - primary_context get_replica_primary_context(mock_replica_ptr rep) - { - return rep->_primary_states; + _parent_split_mgr->on_add_child(req); + _parent_replica->tracker()->wait_outstanding_tasks(); } - bool is_parent_not_in_split() { return (_parent_split_mgr->_child_gpid.get_app_id() == 0); } - - void test_on_add_child() + bool test_parent_check_states() { - _parent_split_mgr->on_add_child(_group_check_req); + bool flag = _parent_split_mgr->parent_check_states(); _parent_replica->tracker()->wait_outstanding_tasks(); + return flag; } - bool test_parent_check_states() { return _parent_split_mgr->parent_check_states(); } - void test_child_copy_prepare_list() { - mock_child_async_learn_states(_parent_replica, false, _decree); + mock_child_async_learn_states(_parent_replica, false, DECREE); std::shared_ptr plist = std::make_shared(_parent_replica, *_mock_plist); _child_split_mgr->child_copy_prepare_list(_mock_learn_state, _mutation_list, _private_log_files, - _total_file_size, + TOTAL_FILE_SIZE, std::move(plist)); _child_replica->tracker()->wait_outstanding_tasks(); } void test_child_learn_states() { - mock_child_async_learn_states(_child_replica, true, _decree); + mock_child_async_learn_states(_child_replica, true, DECREE); _child_split_mgr->child_learn_states( - _mock_learn_state, _mutation_list, _private_log_files, _total_file_size, _decree); + _mock_learn_state, _mutation_list, _private_log_files, TOTAL_FILE_SIZE, DECREE); _child_replica->tracker()->wait_outstanding_tasks(); } @@ -235,7 +226,7 @@ class replica_split_test : public testing::Test { mock_child_async_learn_states(_child_replica, true, 0); _child_split_mgr->child_apply_private_logs( - _private_log_files, _mutation_list, _total_file_size, _decree); + _private_log_files, _mutation_list, TOTAL_FILE_SIZE, DECREE); _child_replica->tracker()->wait_outstanding_tasks(); } @@ -253,17 +244,25 @@ class replica_split_test : public testing::Test _child_replica->tracker()->wait_outstanding_tasks(); } - dsn::error_code test_parent_handle_child_catch_up() + error_code test_parent_handle_child_catch_up(ballot child_ballot) { + _parent_split_mgr->_child_gpid = CHILD_GPID; + + notify_catch_up_request req; + req.child_gpid = CHILD_GPID; + req.parent_gpid = PARENT_GPID; + req.child_ballot = child_ballot; + req.child_address = PRIMARY; + notify_cacth_up_response resp; - _parent_split_mgr->parent_handle_child_catch_up(_catch_up_req, resp); + _parent_split_mgr->parent_handle_child_catch_up(req, resp); _parent_replica->tracker()->wait_outstanding_tasks(); return resp.err; } void test_register_child_on_meta() { - _parent_split_mgr->register_child_on_meta(_init_ballot); + _parent_split_mgr->register_child_on_meta(INIT_BALLOT); _parent_replica->tracker()->wait_outstanding_tasks(); } @@ -283,8 +282,45 @@ class replica_split_test : public testing::Test _parent_replica->tracker()->wait_outstanding_tasks(); } + /// helper functions + void cleanup_prepare_list(mock_replica_ptr rep) { rep->_prepare_list->reset(0); } + void cleanup_child_split_context() + { + _child_replica->_split_states.cleanup(true); + _child_replica->tracker()->wait_outstanding_tasks(); + } + + int32_t child_get_prepare_list_count() { return _child_replica->get_plist()->count(); } + bool child_is_prepare_list_copied() + { + return _child_replica->_split_states.is_prepare_list_copied; + } + bool child_is_caught_up() { return _child_replica->_split_states.is_caught_up; } + + primary_context get_replica_primary_context(mock_replica_ptr rep) + { + return rep->_primary_states; + } + bool parent_sync_send_write_request() + { + return _parent_replica->_primary_states.sync_send_write_request; + } + bool is_parent_not_in_split() { return (_parent_split_mgr->_child_gpid.get_app_id() == 0); } + public: - std::unique_ptr _stub; + const std::string APP_NAME = "split_table"; + const int32_t APP_ID = 2; + const int32_t OLD_PARTITION_COUNT = 8; + const int32_t NEW_PARTITION_COUNT = 16; + const rpc_address PRIMARY = rpc_address("127.0.0.1", 18230); + const rpc_address SECONDARY = rpc_address("127.0.0.2", 10058); + const rpc_address SECONDARY2 = rpc_address("127.0.0.3", 10805); + const gpid PARENT_GPID = gpid(APP_ID, 1); + const gpid CHILD_GPID = gpid(APP_ID, 9); + const ballot INIT_BALLOT = 3; + const decree DECREE = 5; + const int32_t MAX_COUNT = 10; + const uint64_t TOTAL_FILE_SIZE = 100; mock_replica_ptr _parent_replica; mock_replica_ptr _child_replica; @@ -292,114 +328,87 @@ class replica_split_test : public testing::Test std::unique_ptr _child_split_mgr; dsn::app_info _app_info; - dsn::gpid _parent_pid = gpid(2, 1); - dsn::gpid _child_pid = gpid(2, 9); - uint32_t _old_partition_count = 8; - ballot _init_ballot = 3; - decree _decree = 5; - - group_check_request _group_check_req; - notify_catch_up_request _catch_up_req; register_child_request _register_req; std::vector _private_log_files; std::vector _mutation_list; - const uint32_t _max_count = 10; prepare_list *_mock_plist; - const uint64_t _total_file_size = 100; learn_state _mock_learn_state; }; +// TODO(heyuchen): refactor add child unit tests TEST_F(replica_split_test, add_child_wrong_ballot) { - ballot wrong_ballot = 5; - _group_check_req.config.ballot = wrong_ballot; - test_on_add_child(); - ASSERT_EQ(_stub->get_replica(_child_pid), nullptr); + ballot WRONG_BALLOT = 2; + test_on_add_child(WRONG_BALLOT, CHILD_GPID); + ASSERT_EQ(stub->get_replica(CHILD_GPID), nullptr); } TEST_F(replica_split_test, add_child_with_child_existed) { - _parent_split_mgr->set_child_gpid(_child_pid); - test_on_add_child(); - ASSERT_EQ(_stub->get_replica(_child_pid), nullptr); + _parent_split_mgr->set_child_gpid(CHILD_GPID); + test_on_add_child(INIT_BALLOT, CHILD_GPID); + ASSERT_EQ(stub->get_replica(CHILD_GPID), nullptr); } TEST_F(replica_split_test, add_child_succeed) { - fail::setup(); fail::cfg("replica_stub_create_child_replica_if_not_found", "return()"); fail::cfg("replica_child_init_replica", "return()"); - test_on_add_child(); - ASSERT_NE(_stub->get_replica(_child_pid), nullptr); - _stub->get_replica(_child_pid)->tracker()->wait_outstanding_tasks(); - - fail::teardown(); + test_on_add_child(INIT_BALLOT, CHILD_GPID); + ASSERT_NE(stub->get_replica(CHILD_GPID), nullptr); + stub->get_replica(CHILD_GPID)->tracker()->wait_outstanding_tasks(); } -TEST_F(replica_split_test, parent_check_states_with_wrong_status) +// parent_check_states tests +TEST_F(replica_split_test, parent_check_states_tests) { - generate_child(partition_status::PS_PARTITION_SPLIT); - _parent_replica->set_partition_status(partition_status::PS_POTENTIAL_SECONDARY); - - fail::setup(); fail::cfg("replica_stub_split_replica_exec", "return()"); - bool flag = test_parent_check_states(); - ASSERT_FALSE(flag); - fail::teardown(); -} -TEST_F(replica_split_test, parent_check_states) -{ - generate_child(partition_status::PS_PARTITION_SPLIT); - bool flag = test_parent_check_states(); - ASSERT_TRUE(flag); -} - -TEST_F(replica_split_test, copy_prepare_list_with_wrong_status) -{ - generate_child(partition_status::PS_INACTIVE); - mock_child_split_context(_parent_pid, false, false); - - fail::setup(); - fail::cfg("replica_stub_split_replica_exec", "return()"); - test_child_copy_prepare_list(); - fail::teardown(); - - cleanup_prepare_list(_parent_replica); - // TODO(heyuchen): child should be equal to error(after implement child_handle_split_error) + // Test cases: + // - wrong parent partition status + // - check parent states succeed + struct parent_check_state_test + { + partition_status::type parent_status; + bool expected_flag; + } tests[] = {{partition_status::PS_POTENTIAL_SECONDARY, false}, + {partition_status::PS_SECONDARY, true}}; + for (auto test : tests) { + mock_parent_split_context(test.parent_status); + ASSERT_EQ(test_parent_check_states(), test.expected_flag); + } } +// child_copy_prepare_list test TEST_F(replica_split_test, copy_prepare_list_succeed) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, false, false); - - fail::setup(); fail::cfg("replica_stub_split_replica_exec", "return()"); fail::cfg("replica_child_learn_states", "return()"); - test_child_copy_prepare_list(); - fail::teardown(); - partition_split_context split_context = get_split_context(); - ASSERT_EQ(split_context.is_prepare_list_copied, true); - ASSERT_EQ(_child_replica->get_plist()->count(), _max_count); + generate_child(false, false); + ASSERT_FALSE(child_is_prepare_list_copied()); + test_child_copy_prepare_list(); + ASSERT_TRUE(child_is_prepare_list_copied()); + ASSERT_EQ(child_get_prepare_list_count(), MAX_COUNT); cleanup_prepare_list(_parent_replica); cleanup_prepare_list(_child_replica); cleanup_child_split_context(); } +// TODO(heyuchen): refactor child_learn_states unit tests TEST_F(replica_split_test, learn_states_succeed) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, false); + generate_child(true, false); + // mock_child_split_context(true, false); - fail::setup(); + // fail::setup(); fail::cfg("replica_child_apply_private_logs", "return()"); fail::cfg("replica_child_catch_up_states", "return()"); test_child_learn_states(); - fail::teardown(); + // fail::teardown(); + ASSERT_EQ(_child_replica->status(), partition_status::PS_PARTITION_SPLIT); cleanup_prepare_list(_child_replica); cleanup_child_split_context(); @@ -407,125 +416,95 @@ TEST_F(replica_split_test, learn_states_succeed) TEST_F(replica_split_test, learn_states_with_replay_private_log_error) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, false); + generate_child(true, false); - fail::setup(); fail::cfg("replica_child_apply_private_logs", "return(error)"); fail::cfg("replica_child_catch_up_states", "return()"); test_child_learn_states(); - fail::teardown(); - + // TODO(heyuchen): child should be equal to error(after implement child_handle_split_error) cleanup_prepare_list(_child_replica); cleanup_child_split_context(); } +// child_apply_private_logs test TEST_F(replica_split_test, child_apply_private_logs_succeed) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, false); - - fail::setup(); fail::cfg("mutation_log_replay_succeed", "return()"); fail::cfg("replication_app_base_apply_mutation", "return()"); - test_child_apply_private_logs(); - fail::teardown(); - cleanup_prepare_list(_child_replica); - cleanup_child_split_context(); -} - -TEST_F(replica_split_test, catch_up_succeed_with_all_states_learned) -{ - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, false); - - fail::setup(); - fail::cfg("replica_child_notify_catch_up", "return()"); - test_child_catch_up_states(_decree, _decree, _decree); - fail::teardown(); - - partition_split_context split_context = get_split_context(); - ASSERT_EQ(split_context.is_caught_up, true); + generate_child(true, false); + test_child_apply_private_logs(); + ASSERT_EQ(child_get_prepare_list_count(), MAX_COUNT); cleanup_prepare_list(_child_replica); cleanup_child_split_context(); } -TEST_F(replica_split_test, catch_up_succeed_with_learn_in_memory_mutations) +// child_catch_up_states tests +TEST_F(replica_split_test, child_catch_up_states_tests) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, false); - - fail::setup(); fail::cfg("replica_child_notify_catch_up", "return()"); fail::cfg("replication_app_base_apply_mutation", "return()"); - test_child_catch_up_states(_decree, _max_count - 1, 1); - fail::teardown(); - - partition_split_context split_context = get_split_context(); - ASSERT_EQ(split_context.is_caught_up, true); - - cleanup_prepare_list(_child_replica); - cleanup_child_split_context(); -} + generate_child(); -TEST_F(replica_split_test, handle_catch_up_with_ballot_wrong) -{ - mock_notify_catch_up_request(); - _catch_up_req.child_ballot = 1; - - fail::setup(); - fail::cfg("replica_parent_check_sync_point_commit", "return()"); - dsn::error_code err = test_parent_handle_child_catch_up(); - fail::teardown(); - - ASSERT_EQ(err, ERR_INVALID_STATE); -} - -TEST_F(replica_split_test, handle_catch_up_with_not_all_caught_up) -{ - mock_parent_primary_context(false); - mock_notify_catch_up_request(); - - fail::setup(); - fail::cfg("replica_parent_check_sync_point_commit", "return()"); - dsn::error_code err = test_parent_handle_child_catch_up(); - fail::teardown(); - - ASSERT_EQ(err, ERR_OK); - ASSERT_FALSE(get_sync_send_write_request()); + // Test cases: + // - child catch up with all states learned + // - child catch up with in-memory-mutations learned + struct child_catch_up_state_test + { + decree goal_decree; + decree min_decree; + } tests[] = {{DECREE, DECREE}, {MAX_COUNT - 1, 1}}; + for (auto test : tests) { + mock_child_split_context(true, false); + test_child_catch_up_states(DECREE, test.goal_decree, test.min_decree); + ASSERT_TRUE(child_is_caught_up()); + + cleanup_prepare_list(_child_replica); + cleanup_child_split_context(); + } } -TEST_F(replica_split_test, handle_catch_up_with_all_caught_up) +// parent_handle_child_catch_up tests +TEST_F(replica_split_test, parent_handle_catch_up_test) { - mock_parent_primary_context(true); - mock_notify_catch_up_request(); - - fail::setup(); fail::cfg("replica_parent_check_sync_point_commit", "return()"); - dsn::error_code err = test_parent_handle_child_catch_up(); - fail::teardown(); + ballot WRONG_BALLOT = 1; - ASSERT_EQ(err, ERR_OK); - ASSERT_TRUE(get_sync_send_write_request()); + // Test cases: + // - request has wrong ballot + // - not all child caught up + // - all child caught up + struct parent_handle_catch_up_test + { + ballot req_ballot; + bool will_all_caught_up; + error_code expected_err; + bool sync_send_write_request; + } tests[] = {{WRONG_BALLOT, false, ERR_INVALID_STATE, false}, + {INIT_BALLOT, false, ERR_OK, false}, + {INIT_BALLOT, true, ERR_OK, true}}; + for (auto test : tests) { + mock_primary_parent_split_context(false, test.will_all_caught_up); + ASSERT_EQ(test_parent_handle_child_catch_up(test.req_ballot), test.expected_err); + ASSERT_EQ(parent_sync_send_write_request(), test.sync_send_write_request); + } } +// register_child test TEST_F(replica_split_test, register_child_test) { - fail::setup(); fail::cfg("replica_parent_send_register_request", "return()"); test_register_child_on_meta(); - fail::teardown(); - ASSERT_EQ(_parent_replica->status(), partition_status::PS_INACTIVE); ASSERT_EQ(_parent_split_mgr->get_partition_version(), -1); } +// TODO(heyuchen): refactor register child reply TEST_F(replica_split_test, register_child_reply_with_wrong_status) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, true); + generate_child(); + mock_child_split_context(true, true); test_on_register_child_rely(partition_status::PS_PRIMARY, ERR_OK); primary_context parent_primary_states = get_replica_primary_context(_parent_replica); @@ -534,8 +513,8 @@ TEST_F(replica_split_test, register_child_reply_with_wrong_status) TEST_F(replica_split_test, register_child_reply_with_child_registered) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, true); + generate_child(); + mock_child_split_context(true, true); test_on_register_child_rely(partition_status::PS_INACTIVE, ERR_CHILD_REGISTERED); @@ -546,13 +525,11 @@ TEST_F(replica_split_test, register_child_reply_with_child_registered) TEST_F(replica_split_test, register_child_reply_succeed) { - generate_child(partition_status::PS_PARTITION_SPLIT); - mock_child_split_context(_parent_pid, true, true); + generate_child(); + mock_child_split_context(true, true); - fail::setup(); fail::cfg("replica_stub_split_replica_exec", "return()"); test_on_register_child_rely(partition_status::PS_INACTIVE, ERR_OK); - fail::teardown(); ASSERT_TRUE(is_parent_not_in_split()); }