Skip to content

Commit

Permalink
process_test, testutil: ensure timeout is restarted on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jazg committed Mar 10, 2020
1 parent 7ccc1c6 commit f511de7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
40 changes: 36 additions & 4 deletions process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,57 @@ var _ = Describe("Process", func() {
})
})

Context("when not receive anything during the timeout", func() {
Context("when we do not receive a propose during the timeout", func() {
It("should broadcast a nil prevote", func() {
// Init a default process to be modified
By("before reboot")

// Initialise a default process.
processOrigin := NewProcessOrigin(100)

// Replace the broadcaster and start the process
// Replace the broadcaster and start the process.
scheduler := NewMockScheduler(RandomSignatory())
processOrigin.Scheduler = scheduler
process := processOrigin.ToProcess()
process.Start()

// Expect the proposer broadcast a propose message with zero height and round
// Store state for later use.
stateBytes, err := process.MarshalBinary()
Expect(err).ToNot(HaveOccurred())

// Expect the validator to broadcast a nil prevote message.
var message Message
Eventually(processOrigin.BroadcastMessages, 2*time.Second).Should(Receive(&message))
prevote, ok := message.(*Prevote)
Expect(ok).Should(BeTrue())
Expect(prevote.Height()).Should(Equal(block.Height(1)))
Expect(prevote.Round()).Should(BeZero())
Expect(prevote.BlockHash().Equal(block.InvalidHash)).Should(BeTrue())

By("after reboot")

// Initialise a new process using the stored state and
// ensure it times out and broadcasts a nil prevote.
newProcessOrigin := NewProcessOrigin(100)

state := DefaultState(100)
err = state.UnmarshalBinary(stateBytes)
Expect(err).ToNot(HaveOccurred())

newProcessOrigin.UpdateState(state)

// Replace the broadcaster and start the new process.
newScheduler := NewMockScheduler(RandomSignatory())
newProcessOrigin.Scheduler = newScheduler
newProcess := newProcessOrigin.ToProcess()
newProcess.Start()

// Expect the validator to broadcast a nil prevote message.
Eventually(newProcessOrigin.BroadcastMessages, 2*time.Second).Should(Receive(&message))
prevote, ok = message.(*Prevote)
Expect(ok).Should(BeTrue())
Expect(prevote.Height()).Should(Equal(block.Height(1)))
Expect(prevote.Round()).Should(BeZero())
Expect(prevote.BlockHash().Equal(block.InvalidHash)).Should(BeTrue())
})
})
})
Expand Down
4 changes: 4 additions & 0 deletions testutil/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func NewProcessOrigin(f int) ProcessOrigin {
}
}

func (p ProcessOrigin) UpdateState(state process.State) {
p.State = state
}

func (p ProcessOrigin) ToProcess() *process.Process {
return process.New(
logrus.StandardLogger(),
Expand Down

0 comments on commit f511de7

Please sign in to comment.