@@ -3360,7 +3360,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
3360
3360
}
3361
3361
}
3362
3362
3363
- Y_UNIT_TEST ( TestFollowerPromotion) {
3363
+ void TestFollowerPromotion ( bool killDuringPromotion ) {
3364
3364
constexpr int NODES = 3 ;
3365
3365
TTestBasicRuntime runtime (NODES, false );
3366
3366
Setup (runtime, true );
@@ -3391,30 +3391,42 @@ Y_UNIT_TEST_SUITE(THiveTest) {
3391
3391
MakeSureTabletIsUp (runtime, tabletId, i, &pipeConfig, &tabletRolesBefore[i]);
3392
3392
}
3393
3393
int leaders = std::accumulate (tabletRolesBefore.begin (), tabletRolesBefore.end (), 0 , [](int a, bool b) -> int { return b ? a + 1 : a; });
3394
- UNIT_ASSERT_VALUES_EQUAL (leaders, 1 );
3395
3394
int leaderNode = std::find (tabletRolesBefore.begin (), tabletRolesBefore.end (), true ) - tabletRolesBefore.begin ();
3396
- // killing leader
3397
- SendKillLocal (runtime, leaderNode);
3395
+ UNIT_ASSERT_VALUES_EQUAL (leaders, 1 );
3398
3396
{
3399
- TDispatchOptions options;
3400
- options.FinalEvents .emplace_back (TEvLocal::EvTabletStatus);
3401
- runtime.DispatchEvents (options);
3402
- }
3403
- std::array<bool , NODES> tabletRolesIntermediate = {};
3404
- for (int i = 0 ; i < NODES; ++i) {
3405
- if (i != leaderNode) {
3406
- MakeSureTabletIsUp (runtime, tabletId, i, &pipeConfig, &tabletRolesIntermediate[i]);
3407
- } else {
3408
- tabletRolesIntermediate[i] = false ;
3397
+ TBlockEvents<TEvTablet::TEvPromoteToLeader> blockPromote (runtime);
3398
+ // killing leader
3399
+ SendKillLocal (runtime, leaderNode);
3400
+
3401
+ while (blockPromote.empty ()) {
3402
+ runtime.DispatchEvents ({}, TDuration::MilliSeconds (100 ));
3403
+ }
3404
+
3405
+ if (killDuringPromotion) {
3406
+ for (int i = 0 ; i < NODES; ++i) {
3407
+ if (i == leaderNode) {
3408
+ continue ;
3409
+ }
3410
+ TActorId sender = runtime.AllocateEdgeActor (i);
3411
+ runtime.SendToPipe (tabletId, sender, new TEvents::TEvPoisonPill, i, pipeConfig);
3412
+ }
3409
3413
}
3414
+
3415
+ runtime.DispatchEvents ({}, TDuration::MilliSeconds (100 ));
3416
+
3417
+ blockPromote.Stop ().Unblock ();
3418
+ }
3419
+ {
3420
+ TDispatchOptions options;
3421
+ options.FinalEvents .emplace_back (TEvLocal::EvTabletStatus, killDuringPromotion ? 3 : 1 );
3422
+ runtime.DispatchEvents (options, TDuration::MilliSeconds (100 ));
3410
3423
}
3411
- leaders = std::accumulate (tabletRolesIntermediate.begin (), tabletRolesIntermediate.end (), 0 , [](int a, bool b) -> int { return b ? a + 1 : a; });
3412
- int followers = std::accumulate (tabletRolesIntermediate.begin (), tabletRolesIntermediate.end (), 0 , [](int a, bool b) -> int { return b ? a : a + 1 ; });
3413
- UNIT_ASSERT_VALUES_EQUAL (leaders, 1 );
3414
- UNIT_ASSERT_VALUES_EQUAL (followers, 2 );
3415
3424
std::unordered_set<std::pair<TTabletId, TFollowerId>> activeTablets;
3416
3425
TActorId senderA = runtime.AllocateEdgeActor ();
3417
3426
for (int i = 0 ; i < NODES; ++i) {
3427
+ if (i == leaderNode) {
3428
+ continue ;
3429
+ }
3418
3430
TActorId whiteboard = NNodeWhiteboard::MakeNodeWhiteboardServiceId (runtime.GetNodeId (i));
3419
3431
runtime.Send (new IEventHandle (whiteboard, senderA, new NNodeWhiteboard::TEvWhiteboard::TEvTabletStateRequest ()));
3420
3432
TAutoPtr<IEventHandle> handle;
@@ -3429,6 +3441,16 @@ Y_UNIT_TEST_SUITE(THiveTest) {
3429
3441
}
3430
3442
}
3431
3443
UNIT_ASSERT_VALUES_EQUAL (activeTablets.size (), 3 );
3444
+ leaders = std::count_if (activeTablets.begin (), activeTablets.end (), [](auto && p) { return p.second == 0 ; });
3445
+ UNIT_ASSERT_VALUES_EQUAL (leaders, 1 );
3446
+ }
3447
+
3448
+ Y_UNIT_TEST (TestFollowerPromotion) {
3449
+ TestFollowerPromotion (false );
3450
+ }
3451
+
3452
+ Y_UNIT_TEST (TestFollowerPromotionFollowerDies) {
3453
+ TestFollowerPromotion (true );
3432
3454
}
3433
3455
3434
3456
Y_UNIT_TEST (TestManyFollowersOnOneNode) {
0 commit comments