Skip to content

Commit

Permalink
Simplify unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby committed Dec 16, 2024
1 parent f887276 commit 931653f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
1 change: 1 addition & 0 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func StartTimeStampUpdater() {
}

// StopTimeStampUpdater stops the timestamp updater
// WARNING: Make sure to call this function before the program exits, otherwise it will leak goroutines
func StopTimeStampUpdater() {
if stopChan != nil {
close(stopChan)
Expand Down
11 changes: 2 additions & 9 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,14 @@ func Test_StopTimeStampUpdater(t *testing.T) {
// Start the timestamp updater
StartTimeStampUpdater()

now := uint32(time.Now().Unix())
checkTimeStamp(t, now, Timestamp())

// Wait for an increment
time.Sleep(1 * time.Second)
checkTimeStamp(t, now+1, Timestamp())

// Stop the updater
StopTimeStampUpdater()

// Capture the timestamp after stopping
stoppedTime := Timestamp()

// Wait again to see if it updates
time.Sleep(3 * time.Second)
// Wait TO see if it updates
time.Sleep(5 * time.Second)

// It should not have changed since we've stopped the updater
require.Equal(t, stoppedTime, Timestamp(), "timestamp should not change after stopping updater")
Expand Down

0 comments on commit 931653f

Please sign in to comment.