github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/common/test_timer.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package common 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 var _ Timer = (*TimerTest)(nil) 14 15 // TimerTest is a test timer 16 type TimerTest struct { 17 T *testing.T 18 19 CantRegisterTimout bool 20 21 RegisterTimeoutF func(time.Duration) 22 } 23 24 // Default set the default callable value to [cant] 25 func (t *TimerTest) Default(cant bool) { 26 t.CantRegisterTimout = cant 27 } 28 29 func (t *TimerTest) RegisterTimeout(delay time.Duration) { 30 if t.RegisterTimeoutF != nil { 31 t.RegisterTimeoutF(delay) 32 } else if t.CantRegisterTimout && t.T != nil { 33 require.FailNow(t.T, "Unexpectedly called RegisterTimeout") 34 } 35 }