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:
james-prysm
2025-07-11 14:39:52 -05:00
committed by GitHub
parent 83943b5dd8
commit 78f8411ad2
8 changed files with 64 additions and 7 deletions

View File

@@ -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)
}