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

Add e2e test for watch #60331

Merged
merged 1 commit into from
Mar 20, 2018
Merged

Conversation

jennybuckley
Copy link

@jennybuckley jennybuckley commented Feb 23, 2018

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

Added e2e test for watch

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 23, 2018
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 23, 2018
@jennybuckley jennybuckley force-pushed the watch-e2e-test branch 4 times, most recently from 18f60e2 to 3370313 Compare February 24, 2018 00:25
@jennybuckley
Copy link
Author

/test pull-kubernetes-e2e-kops-aws

@jennybuckley
Copy link
Author

/cc @yliaog
/cc @wenjiaswe

@k8s-ci-robot
Copy link
Contributor

@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:

/cc @yliaog
/cc @wenjiaswe

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.

@@ -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() {
Copy link
Contributor

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?

Copy link
Author

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.


func setPodActiveDeadlineSeconds5(p *v1.Pod) {
p.Spec.ActiveDeadlineSeconds = int64ptr(5)
}
Copy link
Contributor

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?

}

func chanThatClosesIn(seconds time.Duration) chan struct{} {
ch := make(chan struct{})
Copy link
Contributor

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?

}

func expectNoEvent(w watch.Interface, eventType watch.EventType, object runtime.Object) {
stop := chanThatClosesIn(10)
Copy link
Contributor

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?

@jennybuckley jennybuckley force-pushed the watch-e2e-test branch 3 times, most recently from 8d139fc to 5a4516e Compare February 26, 2018 20:47
@jennybuckley
Copy link
Author

#60442 merged
/retest

@yliaog
Copy link
Contributor

yliaog commented Feb 26, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 26, 2018
Expect(err).NotTo(HaveOccurred())

// Wait 10s for the watches to take effect
time.Sleep(10 * time.Second)
Copy link
Member

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)?

Copy link
Author

@jennybuckley jennybuckley Feb 27, 2018

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.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2018
@jennybuckley
Copy link
Author

/test all
All tests pass, just trying to see how consistent it is

@jennybuckley
Copy link
Author

/test test pull-kubernetes-e2e-gce

@jennybuckley
Copy link
Author

/test pull-kubernetes-integration
test is passed but it doesn't show up on the checklist

@jennybuckley
Copy link
Author

/retest

for {
select {
case actual := <-w.ResultChan():
if expect.Type == actual.Type && (expect.Object == nil || apiequality.Semantic.DeepEqual(expect.Object, actual.Object)) {
Copy link
Contributor

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).

Copy link
Contributor

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()

Copy link
Author

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...

Copy link
Author

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

Copy link
Contributor

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 :)

@jpbetz
Copy link
Contributor

jpbetz commented Mar 12, 2018

Thanks for bolstering the test coverage here @jennybuckley ! This is much needed.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2018
@janetkuo
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /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 Mar 12, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

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.

@k8s-github-robot k8s-github-robot merged commit c0db49c into kubernetes:master Mar 20, 2018
k8s-github-robot pushed a commit that referenced this pull request Apr 3, 2018
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
```
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants