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

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

@fasmat

Description

@fasmat

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")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions