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