mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
move validator run slot ticker (#15479)
* moving the ticker from chain start to right before the main loop and also after the wait for activation edge case * fixing unit test * adding in a unit test * adding in comment based on potuz's feedback
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package slots
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -701,3 +702,27 @@ func TestToForkVersion(t *testing.T) {
|
||||
require.Equal(t, version.Phase0, result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSlotTickerReplayBehaviour(t *testing.T) {
|
||||
secondsPerslot := uint64(1)
|
||||
st := NewSlotTicker(time.Unix(time.Now().Unix(), 0), secondsPerslot) // 1-second period
|
||||
const ticks = 5
|
||||
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 6*time.Second) // make the timeout very close
|
||||
defer cancel()
|
||||
time.Sleep(time.Duration(ticks) * time.Second) // simulate slow consumer by delaying tick consumption
|
||||
counter := 0
|
||||
prevTime := time.Now()
|
||||
for counter < ticks {
|
||||
select {
|
||||
case <-st.C(): // simulate ticks faster than supposed iteration due to replaying old ticks
|
||||
assert.Equal(t, true, time.Now().Sub(prevTime) < time.Duration(secondsPerslot)*time.Second)
|
||||
counter++
|
||||
prevTime = time.Now()
|
||||
case <-ctx.Done(): // timed out before enough ticks arrived
|
||||
t.Fatalf("expected %d ticks, got %d", ticks, counter)
|
||||
}
|
||||
}
|
||||
|
||||
require.Equal(t, ticks, counter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user