Skip to content

fake clock: expose the number of waiters #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

aojea
Copy link
Member

@aojea aojea commented May 2, 2025

By using Waiters(), tests can wait until the expected number of waiters are present before manipulating the clock's time, ensuring that the goroutine under test has reached a stable state regarding its timers.

/kind feature
/kind flake

What this PR does / why we need it:

When working on kubernetes/kubernetes#131502 it took me a while to find the source of flakiness, the code under test uses two timers and runs in a goroutinge.

There is a race between the test code when updating the fake clock time, that may happen before the timers are reset.

The fake clock already has the HasWaiters() method, but that only works for one timer, leaving a small window for the race to happen. In order to avoid that, we need to expose the actual number of waiters to be able to synchronize the test .

Release note:

NONE

/assign @thockin @danwinship

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 2, 2025
@k8s-ci-robot k8s-ci-robot requested review from cheftako and lavalamp May 2, 2025 00:04
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 2, 2025
@aojea
Copy link
Member Author

aojea commented May 2, 2025

/assign @dims

cross referencing kubernetes/kubernetes@c805d32#r2070948260

@aojea aojea force-pushed the fake_clock_waiters branch from f65dd40 to 7d21cef Compare May 2, 2025 08:11
By using `Waiters()`, tests can wait until the expected number of waiters
are present before manipulating the clock's time, ensuring that the
goroutine under test has reached a stable state regarding its timers.

Change-Id: I64d7b89f5e178a72898885642818215e8ad73a9d
@aojea aojea force-pushed the fake_clock_waiters branch from 7d21cef to 755dc6a Compare May 2, 2025 08:12
@dims
Copy link
Member

dims commented May 2, 2025

/approve
/lgtm

thanks for the review @danwinship

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, dims

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 2, 2025
@k8s-ci-robot k8s-ci-robot merged commit 8884aa7 into kubernetes:master May 2, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants