Skip to content

Commit

Permalink
Try fix for flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Jul 3, 2023
1 parent 8a6ced9 commit 5a24836
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,20 @@ func TestService_Recovery(t *testing.T) {
tempdir := t.TempDir()

// Generate groups of random challenges.
challengeGroupSize := byte(5)
challengeGroupSize := 5
challengeGroups := make([][]challenge, 3)
for g := byte(0); g < 3; g++ {
for g := 0; g < 3; g++ {
challengeGroup := make([]challenge, challengeGroupSize)
for i := byte(0); i < challengeGroupSize; i++ {
for i := 0; i < challengeGroupSize; i++ {
challengeGroup[i] = challenge{
data: bytes.Repeat([]byte{g*10 + i}, 32),
nodeID: bytes.Repeat([]byte{-g*10 - i}, 32),
data: bytes.Repeat([]byte{byte(g*10 + i)}, 32),
nodeID: bytes.Repeat([]byte{byte(-g*10 - i)}, 32),
}
}
challengeGroups[g] = challengeGroup
}

// Create a new service instance.
s, err := service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

submitChallenges := func(roundID string, challenges []challenge) {
submitChallenges := func(s *service.Service, roundID string, challenges []challenge) {
params := s.PowParams()
for _, challenge := range challenges {
nonce, _ := shared.FindSubmitPowNonce(
Expand All @@ -86,14 +82,18 @@ func TestService_Recovery(t *testing.T) {
}
}

// Create a new service instance.
s, err := service.NewService(context.Background(), cfg, tempdir)
req.NoError(err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var eg errgroup.Group
eg.Go(func() error { return s.Run(ctx) })
req.NoError(s.Start(context.Background()))

// Submit challenges to open round (0).
submitChallenges("0", challengeGroups[0])
submitChallenges(s, "0", challengeGroups[0])

// Wait for round 0 to start executing.
req.Eventually(func() bool {
Expand All @@ -103,7 +103,7 @@ func TestService_Recovery(t *testing.T) {
}, cfg.EpochDuration*2, time.Millisecond*100)

// Submit challenges to open round (1).
submitChallenges("1", challengeGroups[1])
submitChallenges(s, "1", challengeGroups[1])

cancel()
req.NoError(eg.Wait())
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestService_Recovery(t *testing.T) {
return info.OpenRoundID == "2"
}, cfg.EpochDuration*2, time.Millisecond*100)

submitChallenges("2", challengeGroups[2])
submitChallenges(s, "2", challengeGroups[2])

for i := 0; i < len(challengeGroups); i++ {
proofMsg := <-s.ProofsChan()
Expand Down

0 comments on commit 5a24836

Please sign in to comment.