Skip to content

Commit

Permalink
Test recovering round in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Sep 7, 2023
1 parent 32da2ab commit 5f289a8
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions registration/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func TestSubmitIdempotence(t *testing.T) {
t.TempDir(),
workerSvc,
registration.WithPowVerifier(verifier),
registration.WithConfig(registration.Config{
MaxRoundMembers: 100,
}),
registration.WithRoundConfig(roundCfg),
)
req.NoError(err)
Expand All @@ -69,7 +66,7 @@ func TestSubmitIdempotence(t *testing.T) {
req.NoError(eg.Wait())
}

func TestService_OpeningRounds(t *testing.T) {
func TestOpeningRounds(t *testing.T) {
t.Run("before genesis", func(t *testing.T) {
reg, err := registration.NewRegistration(
context.Background(),
Expand Down Expand Up @@ -148,7 +145,7 @@ func TestService_OpeningRounds(t *testing.T) {
// Test if Proof of Work challenge is rotated every round.
// The challenge should be changed to the root of PoET proof Merkle tree
// of the previous round.
func TestService_PowChallengeRotation(t *testing.T) {
func TestPowChallengeRotation(t *testing.T) {
genesis := time.Now()

proofs := make(chan shared.NIP, 1)
Expand Down Expand Up @@ -192,3 +189,53 @@ func TestService_PowChallengeRotation(t *testing.T) {
cancel()
require.NoError(t, eg.Wait())
}

func TestRecoveringRoundInProgress(t *testing.T) {
req := require.New(t)
genesis := time.Now()

roundCfg := round_config.Config{
EpochDuration: time.Hour,
PhaseShift: time.Second / 2,
}

ctx, cancel := context.WithCancel(context.Background())

verifier := mocks.NewMockPowVerifier(gomock.NewController(t))
workerSvc := mocks.NewMockWorkerService(gomock.NewController(t))
workerSvc.EXPECT().RegisterForProofs(gomock.Any()).Return(make(<-chan shared.NIP, 1))
workerSvc.EXPECT().ExecuteRound(gomock.Any(), gomock.Eq(uint(0)), gomock.Any()).DoAndReturn(
func(_ context.Context, _ uint, _ []byte) error {
cancel()
return nil
},
)

s, err := registration.NewRegistration(
context.Background(),
genesis,
t.TempDir(),
workerSvc,
registration.WithPowVerifier(verifier),
registration.WithRoundConfig(roundCfg),
)
req.NoError(err)

defer cancel()
var eg errgroup.Group
eg.Go(func() error { return s.Run(ctx) })

req.NoError(eg.Wait())

// Restart the registration service.
// The round in progress should be recovered and executed again.
ctx, cancel = context.WithCancel(context.Background())
workerSvc.EXPECT().RegisterForProofs(gomock.Any()).Return(make(<-chan shared.NIP, 1))
workerSvc.EXPECT().ExecuteRound(gomock.Any(), gomock.Eq(uint(0)), gomock.Any()).DoAndReturn(
func(_ context.Context, _ uint, _ []byte) error {
cancel()
return nil
},
)
req.NoError(s.Run(ctx))
}

0 comments on commit 5f289a8

Please sign in to comment.