2021-09-15 00:09:04 +00:00
|
|
|
package slots
|
2020-06-12 18:47:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime "github.com/prysmaticlabs/prysm/time"
|
2021-09-02 20:41:01 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-06-12 18:47:18 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCountdownToGenesis(t *testing.T) {
|
2021-09-02 20:41:01 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
|
2020-06-12 18:47:18 +00:00
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
params.SetupTestConfigCleanup(t)
|
|
|
|
config := params.BeaconConfig()
|
|
|
|
config.GenesisCountdownInterval = time.Millisecond * 500
|
|
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
|
2020-09-04 18:07:50 +00:00
|
|
|
t.Run("normal countdown", func(t *testing.T) {
|
|
|
|
defer hook.Reset()
|
|
|
|
firstStringResult := "1s until chain genesis"
|
|
|
|
genesisReached := "Chain genesis time reached"
|
|
|
|
CountdownToGenesis(
|
|
|
|
context.Background(),
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime.Now().Add(2*time.Second),
|
2020-09-04 18:07:50 +00:00
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
2020-12-01 00:06:16 +00:00
|
|
|
[32]byte{},
|
2020-09-04 18:07:50 +00:00
|
|
|
)
|
|
|
|
require.LogsContain(t, hook, firstStringResult)
|
|
|
|
require.LogsContain(t, hook, genesisReached)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("close context", func(t *testing.T) {
|
|
|
|
defer hook.Reset()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
|
|
|
time.AfterFunc(1500*time.Millisecond, func() {
|
|
|
|
cancel()
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
CountdownToGenesis(
|
|
|
|
ctx,
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime.Now().Add(5*time.Second),
|
2020-09-04 18:07:50 +00:00
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
2020-12-01 00:06:16 +00:00
|
|
|
[32]byte{},
|
2020-09-04 18:07:50 +00:00
|
|
|
)
|
|
|
|
require.LogsContain(t, hook, "4s until chain genesis")
|
2021-09-02 20:41:01 +00:00
|
|
|
require.LogsContain(t, hook, "3s until chain genesis")
|
2020-09-04 18:07:50 +00:00
|
|
|
require.LogsContain(t, hook, "Context closed, exiting routine")
|
|
|
|
require.LogsDoNotContain(t, hook, "Chain genesis time reached")
|
|
|
|
})
|
2020-06-12 18:47:18 +00:00
|
|
|
}
|