diff --git a/common/countdown/countdown.go b/common/countdown/countdown.go index 6f941adaa8..99ca5bd277 100644 --- a/common/countdown/countdown.go +++ b/common/countdown/countdown.go @@ -12,7 +12,7 @@ type CountdownTimer struct { lock sync.RWMutex // Protects the Initilised field resetc chan int quitc chan chan struct{} - Initilised bool + initilised bool timeoutDuration time.Duration // Triggered when the countdown timer timeout for the `timeoutDuration` period, it will pass current timestamp to the callback function OnTimeoutFn func(time time.Time) error @@ -22,7 +22,7 @@ func NewCountDown(duration time.Duration) *CountdownTimer { return &CountdownTimer{ resetc: make(chan int), quitc: make(chan chan struct{}), - Initilised: false, + initilised: false, timeoutDuration: duration, } } @@ -73,11 +73,11 @@ func (t *CountdownTimer) startTimer() { func (t *CountdownTimer) setInitilised(value bool) { t.lock.Lock() defer t.lock.Unlock() - t.Initilised = value + t.initilised = value } func (t *CountdownTimer) getInitilisedValue() bool { t.lock.Lock() defer t.lock.Unlock() - return t.Initilised + return t.initilised } diff --git a/common/countdown/countdown_test.go b/common/countdown/countdown_test.go index 2ca60192e4..caec7a2688 100644 --- a/common/countdown/countdown_test.go +++ b/common/countdown/countdown_test.go @@ -33,10 +33,10 @@ func TestCountdownShouldReset(t *testing.T) { countdown := NewCountDown(5000 * time.Millisecond) countdown.OnTimeoutFn = OnTimeoutFn // Check countdown did not start - assert.False(t, countdown.Initilised) + assert.False(t, countdown.getInitilisedValue()) countdown.Reset() // Now the countdown should already started - assert.True(t, countdown.Initilised) + assert.True(t, countdown.getInitilisedValue()) expectedCalledTime := time.Now().Add(9000 * time.Millisecond) resetTimer := time.NewTimer(4000 * time.Millisecond) @@ -46,7 +46,7 @@ firstReset: case <-called: if time.Now().After(expectedCalledTime) { // Make sure the countdown runs forever - assert.True(t, countdown.Initilised) + assert.True(t, countdown.getInitilisedValue()) fmt.Println("Correctly reset the countdown once") } else { t.Fatalf("Countdown did not reset correctly first time") @@ -58,12 +58,12 @@ firstReset: } // Now the countdown is paused after calling the callback function, let's reset it again - assert.True(t, countdown.Initilised) + assert.True(t, countdown.getInitilisedValue()) expectedTimeAfterReset := time.Now().Add(5000 * time.Millisecond) countdown.Reset() <-called // Always initilised - assert.True(t, countdown.Initilised) + assert.True(t, countdown.getInitilisedValue()) if time.Now().After(expectedTimeAfterReset) { fmt.Println("Correctly reset the countdown second time") } else { @@ -81,13 +81,13 @@ func TestCountdownShouldBeAbleToStop(t *testing.T) { countdown := NewCountDown(5000 * time.Millisecond) countdown.OnTimeoutFn = OnTimeoutFn // Check countdown did not start - assert.False(t, countdown.Initilised) + assert.False(t, countdown.getInitilisedValue()) countdown.Reset() // Now the countdown should already started - assert.True(t, countdown.Initilised) + assert.True(t, countdown.getInitilisedValue()) // Try manually stop the timer before it triggers the callback stopTimer := time.NewTimer(4000 * time.Millisecond) <-stopTimer.C countdown.StopTimer() - assert.False(t, countdown.Initilised) + assert.False(t, countdown.getInitilisedValue()) }