Fix countdown timer (#9484)

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
Kirill Fedoseev 2021-09-02 23:41:01 +03:00 committed by GitHub
parent c45fe5cc1c
commit f319535af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -41,14 +41,14 @@ func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValid
ticker = time.NewTicker(time.Second)
secondTimerActivated = true
}
if timeRemaining >= time.Second {
log.WithFields(logFields).Infof(
"%s until chain genesis",
timeRemaining.Truncate(time.Second),
)
}
select {
case <-ticker.C:
if timeRemaining >= time.Second {
log.WithFields(logFields).Infof(
"%s until chain genesis",
timeRemaining.Truncate(time.Second),
)
}
case <-ctx.Done():
log.Debug("Context closed, exiting routine")
return

View File

@ -8,10 +8,13 @@ import (
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/shared/timeutils"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestCountdownToGenesis(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
hook := logTest.NewGlobal()
params.SetupTestConfigCleanup(t)
config := params.BeaconConfig()
@ -47,6 +50,7 @@ func TestCountdownToGenesis(t *testing.T) {
[32]byte{},
)
require.LogsContain(t, hook, "4s until chain genesis")
require.LogsContain(t, hook, "3s until chain genesis")
require.LogsContain(t, hook, "Context closed, exiting routine")
require.LogsDoNotContain(t, hook, "Chain genesis time reached")
})