Added UT to early buffer in Hare
@@ -447,15 +447,34 @@ func TestConsensusProcess_currentRound(t *testing.T) {
}
func TestConsensusProcess_onEarlyMessage(t *testing.T) {
+ r := require.New(t)
proc := generateConsensusProcess(t)
m := BuildPreRoundMsg(generateSigning(t), NewDefaultEmptySet())
proc.advanceToNextRound()
proc.onEarlyMessage(buildMessage(nil))
- assert.Equal(t, 0, len(proc.pending))
+ r.Equal(0, len(proc.pending))
proc.onEarlyMessage(m)
- assert.Equal(t, 1, len(proc.pending))
+ r.Equal(1, len(proc.pending))
proc.onEarlyMessage(m)
- assert.Equal(t, 1, len(proc.pending))
+ r.Equal(1, len(proc.pending))
+ m2 := BuildPreRoundMsg(generateSigning(t), NewDefaultEmptySet())
+ proc.onEarlyMessage(m2)
+ m3 := BuildPreRoundMsg(generateSigning(t), NewDefaultEmptySet())
+ proc.onEarlyMessage(m3)
+ r.Equal(3, len(proc.pending))
+ proc.onRoundBegin()
+
+ // make sure we wait enough for the go routine to be executed
+ timeout := time.NewTimer(1 * time.Second)
+ tk := time.NewTicker(100 * time.Microsecond)
+ select {
+ case <-timeout.C:
+ r.Equal(0, len(proc.pending))
+ case <-tk.C:
+ if 0 == len(proc.pending) {
+ return
+ }
+ }
}
func TestProcOutput_Id(t *testing.T) {
