-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 cache sync timeout functionality #1428
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:master
from
alvaroaleman:fix-cachesync
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ var _ = Describe("Source", func() { | |
}, | ||
}, q) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(instance.WaitForSync(context.Background())).NotTo(HaveOccurred()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to call WaitForSync here because before that finished, the Informer won't have the EventHandler attached. Not waiting makes the test racy. |
||
|
||
i, err := ic.FakeInformerFor(&corev1.Pod{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
@@ -133,6 +134,7 @@ var _ = Describe("Source", func() { | |
}, | ||
}, q) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(instance.WaitForSync(context.Background())).NotTo(HaveOccurred()) | ||
|
||
i, err := ic.FakeInformerFor(&corev1.Pod{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
@@ -178,6 +180,7 @@ var _ = Describe("Source", func() { | |
}, | ||
}, q) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(instance.WaitForSync(context.Background())).NotTo(HaveOccurred()) | ||
|
||
i, err := ic.FakeInformerFor(&corev1.Pod{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
@@ -208,10 +211,11 @@ var _ = Describe("Source", func() { | |
}) | ||
|
||
It("should return an error if syncing fails", func(done Done) { | ||
instance := source.Kind{} | ||
instance := source.Kind{Type: &corev1.Pod{}} | ||
f := false | ||
Expect(instance.InjectCache(&informertest.FakeInformers{Synced: &f})).To(Succeed()) | ||
err := instance.WaitForSync(nil) | ||
Expect(instance.Start(context.Background(), nil, nil)).NotTo(HaveOccurred()) | ||
err := instance.WaitForSync(context.Background()) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(Equal("cache did not sync")) | ||
|
||
|
@@ -220,7 +224,7 @@ var _ = Describe("Source", func() { | |
}) | ||
|
||
Context("for a Kind not in the cache", func() { | ||
It("should return an error when Start is called", func(done Done) { | ||
It("should return an error when WaitForSync is called", func(done Done) { | ||
ic.Error = fmt.Errorf("test error") | ||
q := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "test") | ||
|
||
|
@@ -229,7 +233,8 @@ var _ = Describe("Source", func() { | |
} | ||
Expect(instance.InjectCache(ic)).To(Succeed()) | ||
err := instance.Start(ctx, handler.Funcs{}, q) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(instance.WaitForSync(context.Background())).To(HaveOccurred()) | ||
|
||
close(done) | ||
}) | ||
|
@@ -246,8 +251,9 @@ var _ = Describe("Source", func() { | |
|
||
It("should return an error if syncing fails", func(done Done) { | ||
f := false | ||
instance := source.NewKindWithCache(nil, &informertest.FakeInformers{Synced: &f}) | ||
err := instance.WaitForSync(nil) | ||
instance := source.NewKindWithCache(&corev1.Pod{}, &informertest.FakeInformers{Synced: &f}) | ||
Expect(instance.Start(context.Background(), nil, nil)).NotTo(HaveOccurred()) | ||
err := instance.WaitForSync(context.Background()) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(Equal("cache did not sync")) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing this test ever tested was that
controller.Start
with a cancelled context doesn't error. With the changes in this PR however it will always error because the context passed from the Controller to WaitForSync is cancelledThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case do you think it's worth having a test case that checks that an error is always returned if the context is cancelled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO the only thing someone who starts a Controller with a cancelled context can realistically expect is that it ends quickly, if it errors or not along the way ends up being an implementation detail. It is not going to result in anything useful.