diff --git a/pkg/registry/common/refresh/nse_registry_client_test.go b/pkg/registry/common/refresh/nse_registry_client_test.go index f0f27457b..0588be621 100644 --- a/pkg/registry/common/refresh/nse_registry_client_test.go +++ b/pkg/registry/common/refresh/nse_registry_client_test.go @@ -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 { @@ -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 { @@ -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) @@ -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) diff --git a/pkg/tools/clockmock/mock.go b/pkg/tools/clockmock/mock.go index 89db96268..98362d006 100644 --- a/pkg/tools/clockmock/mock.go +++ b/pkg/tools/clockmock/mock.go @@ -20,7 +20,6 @@ package clockmock import ( "context" "sync" - "sync/atomic" "time" libclock "github.com/benbjohnson/clock" @@ -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 @@ -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) { @@ -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() @@ -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() @@ -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()