-
Notifications
You must be signed in to change notification settings - Fork 39.7k
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
Add e2e test for watch #60331
Add e2e test for watch #60331
Conversation
18f60e2
to
3370313
Compare
/test pull-kubernetes-e2e-kops-aws |
/cc @yliaog |
@jennybuckley: GitHub didn't allow me to request PR reviews from the following users: wenjiaswe. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
test/e2e/apimachinery/watch.go
Outdated
@@ -43,7 +41,7 @@ const ( | |||
var _ = SIGDescribe("Watchers", func() { | |||
f := framework.NewDefaultFramework("watch") | |||
|
|||
It("should concurrently observe add, update, and delete events on pods", func() { | |||
It("should observe add, update, and delete events on pods", func() { |
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.
what's the reason to make it serial?
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.
I think it used too much code just maintaining the concurrency and the test should be valid either way. Also, it's not serial in the sense that it can't be run at the same time as other tests, so the length of time it takes to run shouldn't matter much.
test/e2e/apimachinery/watch.go
Outdated
|
||
func setPodActiveDeadlineSeconds5(p *v1.Pod) { | ||
p.Spec.ActiveDeadlineSeconds = int64ptr(5) | ||
} |
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.
maybe better to merge the above two func into one, and add a new param for deadline seconds?
test/e2e/apimachinery/watch.go
Outdated
} | ||
|
||
func chanThatClosesIn(seconds time.Duration) chan struct{} { | ||
ch := make(chan struct{}) |
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.
what about using Timer directly?
test/e2e/apimachinery/watch.go
Outdated
} | ||
|
||
func expectNoEvent(w watch.Interface, eventType watch.EventType, object runtime.Object) { | ||
stop := chanThatClosesIn(10) |
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.
seems most code logic are the same for the two func, what about merge them into one?
8d139fc
to
5a4516e
Compare
#60442 merged |
/lgtm |
test/e2e/apimachinery/watch.go
Outdated
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Wait 10s for the watches to take effect | ||
time.Sleep(10 * time.Second) |
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.
Are there better way to do this (e.g. polling and check watcher's status)?
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.
After some looking, I think the .Watch() call won't return until the watch has taken effect. The test still passes without this line.
/test all |
/test test pull-kubernetes-e2e-gce |
/test pull-kubernetes-integration |
/retest |
test/e2e/apimachinery/watch.go
Outdated
for { | ||
select { | ||
case actual := <-w.ResultChan(): | ||
if expect.Type == actual.Type && (expect.Object == nil || apiequality.Semantic.DeepEqual(expect.Object, actual.Object)) { |
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.
When running this e2e test locally it fails with the error: "Timed out waiting for expected event: {DELETED <nil>}"
. The comparison expect.Object == nil
doesn't evaluate to true in the case of delete as we would expect, and this leads to a timeout. This is because expect.Object
is an interface whose underlying value is nil but the interface itself is non-nil (https://golang.org/doc/faq#nil_error).
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.
A safer way to do this would be reflect.ValueOf(expect.Object).IsNil()
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.
Thanks for catching this, now I'm just confused how it was passing on my computer and on the pre-submit test...
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.
I can't seem to replicate that behavior, but I still updated the test to be more explicit,
https://play.golang.org/p/_FYAn6o_kTQ
It seems like reflect.ValueOf(expect.Object).IsNil()
causes a panic when used on a nil value
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.
Alright! I think it was occurring in mine due to some other reasons. This looks fine, thanks for the example :)
351be30
to
3b2472a
Compare
Thanks for bolstering the test coverage here @jennybuckley ! This is much needed. /lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: janetkuo, jennybuckley, jpbetz, yliaog 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 |
/retest Review the full test history for this PR. Silence the bot with an |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 60457, 60331, 54970, 58731, 60562). If you want to cherry-pick this change to another branch, please follow the instructions here. |
Automatic merge from submit-queue (batch tested with PRs 61404, 61025). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add e2e test for CRD Watch **What this PR does / why we need it**: This adds an e2e test to watch for custom resources. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #55538 **Special notes for your reviewer**: This PR depends on some functions from #60331, and shouldn't be merged before that one gets merged. **Release note**: ```release-note Add e2e test for CRD Watch ```
What this PR does / why we need it:
Currently watch is only tested by kubectl tests, but all clients of kubernetes should be able to reliably watch resources for changes. This test should be able to accommodate testing watch for custom resources without many changes.
/sig api-machinery