You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
after 2 fakeclock seconds
after 1 fakeclock second
When clk is changed to clock.RealClock{} (playground), the println lines are in correct order (1 -> 2).
What you expected to happen:
Intuitively, one would expect clk.Sleep(duration) to be identical to <-clk.After(duration). However, (*FakeClock).Sleep actually calls clk.Step instead, which immediately modifies the clock.
Suggested fix:
It would be a huge BC break to many testing packages if (*FakeClock).Sleep is changed to be passive. Documentation improvement would suffice, although deprecating Sleep would be great since Sleep doesn't always do what users intend. (imo, clk.Step is usually only intended in the main control flow of the unit test rather than other goroutines, so calling clk.Sleep from non-testing code is often unintended).
Alternatively, consider adding a ref-counted clock, where Sleep and After have identical behavior and the clock is only stepped when all refs are sleeping.
What happened:
Consider the following code (playground):
The code above prints
When
clk
is changed toclock.RealClock{}
(playground), theprintln
lines are in correct order (1 -> 2).What you expected to happen:
Intuitively, one would expect
clk.Sleep(duration)
to be identical to<-clk.After(duration)
. However,(*FakeClock).Sleep
actually callsclk.Step
instead, which immediately modifies the clock.Suggested fix:
It would be a huge BC break to many testing packages if
(*FakeClock).Sleep
is changed to be passive. Documentation improvement would suffice, although deprecatingSleep
would be great sinceSleep
doesn't always do what users intend. (imo,clk.Step
is usually only intended in the main control flow of the unit test rather than other goroutines, so callingclk.Sleep
from non-testing code is often unintended).Alternatively, consider adding a ref-counted clock, where
Sleep
andAfter
have identical behavior and the clock is only stepped when all refs are sleeping.Environment:
k8s.io/utils: fe8a2dd
The text was updated successfully, but these errors were encountered: