Skip to content
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

Fix cancelling timers in FakeClock package #37

Merged
merged 2 commits into from
Jun 21, 2018

Conversation

munnerz
Copy link
Member

@munnerz munnerz commented Jun 7, 2018

This existing timer implementation used for testing does not properly support cancellation.

This is because of how pointers and copies are handled in the FakeClock structure.

Here, we determine whether to still retain a timer by comparing the registered waiters and the current timer/waiter, and if they do not match, we retain the timer (as it is not the timer being cancelled): https://github.com/kubernetes/utils/blob/master/clock/testing/fake_clock.go#L225-L240

However, we instantiate the fakeClockWaiter as a non-pointer within the Timer structure, and record this structure in a slice stored on the FakeClock. You can see that happening here: https://github.com/kubernetes/utils/blob/master/clock/testing/fake_clock.go#L89-L94

The issue is that on L94, we actually create a copy of the fakeClockWaiter, which means that the comparison on L232 will never match, and so all timers will be retained.

This PR changes the slice in the FakeClock to be a slice of pointers, which resolves the issue.
Unit tests still pass with this new adapted version, and my own tests that rely on this package are now passing too.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 7, 2018
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 7, 2018
@munnerz
Copy link
Member Author

munnerz commented Jun 7, 2018

I've also added a unit test to verify that timer cancellation works 😄

@munnerz
Copy link
Member Author

munnerz commented Jun 7, 2018

/cc @apelisse
/cc @mengqiy

Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Looks good to me, thanks for adding a test.

I'll let someone else merge.

@munnerz
Copy link
Member Author

munnerz commented Jun 21, 2018

Ping on this - I'd really like to use this package for unit tests in cert-manager.

@apelisse who should I chase to get another review/the merge button hit?

@apelisse
Copy link
Member

apelisse commented Jun 21, 2018

@thockin Do you want to merge that? I'll merge it otherwise.

@thockin
Copy link
Member

thockin commented Jun 21, 2018

Seems sane to me. You are fully empowered to merge changes such as this, @apelisse :)

@thockin thockin merged commit 733eca4 into kubernetes:master Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

4 participants