Skip to content

FakeClock does not behave like RealClock on Go >= 1.23 #98

@TheSven73

Description

@TheSven73

Ever since Go 1.23, the fake and real clocks behave differently:

func Test_RealTimer(t *testing.T) {
	c := clockwork.NewRealClock()
	test_drainTimer(t, c, func() {
		c.Sleep(time.Second)
	})
}

func Test_FakeTimer(t *testing.T) {
	c := clockwork.NewFakeClock()
	test_drainTimer(t, c, func() {
		c.Advance(time.Second)
	})
}

func test_drainTimer(t *testing.T, c clockwork.Clock, advanceTime func()) {
	timer := c.NewTimer(time.Second)
	advanceTime()
	timer.Reset(time.Second)
	if len(timer.Chan()) > 0 {
		t.Fatal("timer didn't reset, but fired immediately")
	}
}

On Go 1.22 Fake and Real give an identical and correct result (the timer should be drained)

main_test.go:111: timer didn't reset, but fired immediately
main_test.go:111: timer didn't reset, but fired immediately

However on Go 1.23, Fake and Real behave differently:

main_test.go:111: timer didn't reset, but fired immediately

See also #84

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