Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Mocked time.After and time.Timer are not monotonic #48

Open
fasmat opened this issue Feb 3, 2023 · 1 comment
Open

Mocked time.After and time.Timer are not monotonic #48

fasmat opened this issue Feb 3, 2023 · 1 comment

Comments

@fasmat
Copy link

fasmat commented Feb 3, 2023

The standard library versions of these behave monotonic, meaning that if I change the system clock while the program is running time.After and time.Timer still fire after the time I programmed them to. The mocked variants don't behave this way:

now := time.Now()

mClock := clock.NewMock()
mClock.Set(now)

ch := mClock.After(10 * time.Second)
mClock.Set(now.Add(-1 * time.Minute))

mClock.Add(15 * time.Second)

select {
case <-ch:
	fmt.Println("it works!")
default:
	fmt.Println("mocked After is not monotonic")
}
@djmitche
Copy link
Collaborator

In terms of the mock pointers, how would you see this working? When the clock is set back, would we subtract that amount from all of the pending timers?

Also, I'm not sure how this relates to testing - the m.Set method isn't available on a "real" clock.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants