Skip to content

Commit

Permalink
Remove clockMock.IsTimerSet
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Apr 22, 2021
1 parent df12876 commit 2f577e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pkg/registry/common/refresh/nse_registry_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestNewNetworkServiceEndpointRegistryClient(t *testing.T) {
require.NoError(t, err)

// Wait for the Refresh goroutine to start
require.Eventually(t, clockMock.IsTimerSet, testWait, testTick)
time.Sleep(testTick)

clockMock.Add(expireTimeout)
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -118,7 +118,7 @@ func Test_RefreshNSEClient_CalledRegisterTwice(t *testing.T) {
require.NoError(t, err)

// Wait for the Refresh goroutine to start
require.Eventually(t, clockMock.IsTimerSet, testWait, testTick)
time.Sleep(testTick)

clockMock.Add(expireTimeout)
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -163,7 +163,7 @@ func Test_RefreshNSEClient_ShouldOverrideNameAndDuration(t *testing.T) {
require.NoError(t, err)

// Wait for the Refresh goroutine to start
require.Eventually(t, clockMock.IsTimerSet, testWait, testTick)
time.Sleep(testTick)

for i := 1; i <= 3; i++ {
count := int32(i)
Expand Down Expand Up @@ -202,7 +202,7 @@ func Test_RefreshNSEClient_SetsCorrectExpireTime(t *testing.T) {
require.NoError(t, err)

// Wait for the Refresh goroutine to start
require.Eventually(t, clockMock.IsTimerSet, testWait, testTick)
time.Sleep(testTick)

for i := 1; i <= 3; i++ {
count := int32(i)
Expand Down
13 changes: 0 additions & 13 deletions pkg/tools/clockmock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package clockmock
import (
"context"
"sync"
"sync/atomic"
"time"

libclock "github.com/benbjohnson/clock"
Expand All @@ -34,7 +33,6 @@ var _ clock.Clock = (*Mock)(nil)
type Mock struct {
lock sync.RWMutex
mock *libclock.Mock
flag int32
}

// NewMock returns a new mocked clock
Expand All @@ -44,11 +42,6 @@ func NewMock() *Mock {
}
}

// IsTimerSet returns if any timer/ticker has ever been set on mock.
func (m *Mock) IsTimerSet() bool {
return atomic.LoadInt32(&m.flag) != 0
}

// Set sets the current time of the mock clock to a specific one.
// This should only be called from a single goroutine at a time.
func (m *Mock) Set(t time.Time) {
Expand Down Expand Up @@ -89,8 +82,6 @@ func (m *Mock) Sleep(d time.Duration) {

// Timer returns a timer that will fire when the mock current time becomes > m.Now().Add(d)
func (m *Mock) Timer(d time.Duration) clock.Timer {
defer atomic.StoreInt32(&m.flag, 1)

m.lock.RLock()
defer m.lock.RUnlock()

Expand All @@ -113,8 +104,6 @@ func (m *Mock) AfterFunc(d time.Duration, f func()) clock.Timer {
}

func (m *Mock) afterFunc(d time.Duration, f func()) clock.Timer {
defer atomic.StoreInt32(&m.flag, 1)

return &mockTimer{
Timer: m.mock.AfterFunc(safeDuration(d), func() {
go f()
Expand All @@ -124,8 +113,6 @@ func (m *Mock) afterFunc(d time.Duration, f func()) clock.Timer {

// Ticker returns a ticker that will fire every time when the mock current time becomes > mock previous time + d
func (m *Mock) Ticker(d time.Duration) clock.Ticker {
defer atomic.StoreInt32(&m.flag, 1)

m.lock.RLock()
defer m.lock.RUnlock()

Expand Down

0 comments on commit 2f577e1

Please sign in to comment.