Open SOF3 opened 4 months ago
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle stale
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
/remove-lifecycle stale
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: fe8a2dddb1d00a41a4a4132ba33cb324aa7cd71c