github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/chaser/chasing_delay_test.go (about) 1 // Copyright 2020 Insolar Network Ltd. 2 // All rights reserved. 3 // This material is licensed under the Insolar License version 1.0, 4 // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md. 5 6 package chaser 7 8 import ( 9 "testing" 10 "time" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestNewChasingTimer(t *testing.T) { 16 chasingDelay := time.Second 17 ct := NewChasingTimer(chasingDelay) 18 require.Equal(t, chasingDelay, ct.chasingDelay) 19 } 20 21 func TestIsEnabled(t *testing.T) { 22 ct := NewChasingTimer(time.Second) 23 require.True(t, ct.IsEnabled()) 24 25 ct = NewChasingTimer(0) 26 require.False(t, ct.IsEnabled()) 27 28 ct = NewChasingTimer(-time.Second) 29 require.False(t, ct.IsEnabled()) 30 } 31 32 func TestWasStarted(t *testing.T) { 33 ct := NewChasingTimer(time.Second) 34 require.False(t, ct.WasStarted()) 35 36 ct.timer = time.NewTimer(time.Second) 37 require.True(t, ct.WasStarted()) 38 } 39 40 func TestRestartChase(t *testing.T) { 41 ct := NewChasingTimer(-time.Second) 42 ct.RestartChase() 43 require.Nil(t, ct.timer) 44 45 ct = NewChasingTimer(0) 46 ct.RestartChase() 47 require.Nil(t, ct.timer) 48 49 ct = NewChasingTimer(time.Microsecond) 50 ct.RestartChase() 51 require.NotNil(t, ct.timer) 52 53 ct.RestartChase() 54 require.NotNil(t, ct.timer) 55 } 56 57 func TestChannel(t *testing.T) { 58 ct := NewChasingTimer(0) 59 require.Nil(t, ct.Channel()) 60 61 ct = NewChasingTimer(time.Microsecond) 62 ct.RestartChase() 63 require.NotNil(t, ct.Channel()) 64 }