Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp authored and ti-chi-bot committed May 30, 2024
1 parent d20157f commit 2a32004
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/election/leadership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,24 @@ func TestCampaignTimes(t *testing.T) {

// all the campaign times are within the timeout.
campaignTimesRecordTimeout = 10 * time.Second
defer func() {
campaignTimesRecordTimeout = 5 * time.Minute
}()
for i := 0; i < 3; i++ {
leadership.AddCampaignTimes()
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
}
re.Equal(3, leadership.GetCampaignTimesNum())

// only the last 2 records are valid.
campaignTimesRecordTimeout = 2 * time.Second
campaignTimesRecordTimeout = 200 * time.Millisecond
for i := 0; i < 3; i++ {
leadership.AddCampaignTimes()
time.Sleep(time.Second)
time.Sleep(100 * time.Millisecond)
}
re.Equal(2, leadership.GetCampaignTimesNum())

time.Sleep(2 * time.Second)
time.Sleep(200 * time.Millisecond)
// need to wait for the next addCampaignTimes to update the campaign time.
re.Equal(2, leadership.GetCampaignTimesNum())
// check campaign leader frequency.
Expand Down

0 comments on commit 2a32004

Please sign in to comment.