Code change:
} } <ins> func TestFakeTimer(t *testing.T) { tc := NewFakeClock(time.Now()) if tc.HasWaiters() { t.Errorf("unexpected waiter?") } oneSec := tc.NewTimer(time.Second) twoSec := tc.NewTimer(time.Second * 2) treSec := tc.NewTimer(time.Second * 3) if !tc.HasWaiters() { t.Errorf("unexpected lack of waiter?") } select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } tc.Step(999999999 * time.Nanosecond) // t=.999,999,999 select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } tc.Step(time.Nanosecond) // t=1 select { case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } select { case <-oneSec.C(): // Expected! default: t.Errorf("unexpected channel non-read") } tc.Step(time.Nanosecond) // t=1.000,000,001 select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } if oneSec.Stop() { t.Errorf("Expected oneSec.Stop() to return false") } if !twoSec.Stop() { t.Errorf("Expected twoSec.Stop() to return true") } tc.Step(time.Second) // t=2.000,000,001 select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } if twoSec.Reset(time.Second) { t.Errorf("Expected twoSec.Reset() to return false") } if !treSec.Reset(time.Second) { t.Errorf("Expected treSec.Reset() to return true") } tc.Step(time.Nanosecond * 999999999) // t=3.0 select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") case <-treSec.C(): t.Errorf("unexpected channel read") default: } tc.Step(time.Nanosecond) // t=3.000,000,001 select { case <-oneSec.C(): t.Errorf("unexpected channel read") case <-twoSec.C(): t.Errorf("unexpected channel read") default: } select { case <-treSec.C(): // Expected! default: t.Errorf("unexpected channel non-read") } } </ins> func TestFakeTick(t *testing.T) { tc := NewFakeClock(time.Now()) if tc.HasWaiters() {

Related discussion:
text: <!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: I was writing a variant of clock.FakeClock, and noticed a couple of bugs in . Look at the pointer comparison in --- the two pointers will never be equal, but the author clearly expected equality when is the index of the fakeClockWaiter corresponding to the fakeTimer. The two pointers will never be equal because one is a pointer into the fakeClock's slice while the other pointer is to a field of the . The consequence of this bug is that the Stop function is ineffective. Also, determines the returned value based on the original copy of the waiter, which --- being a copy --- did not get updated if/when the waiter fired. Note also that does not exercise FakeClock::NewTimer at all. What you expected to happen: I expected FakeClock Timers to work properly. How to reproduce it (as minimally and precisely as possible): Use the TestFakeTimer func introduced in Anything else we need to know?: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
The fake timer's Reset() method also does not work correctly.