-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Make integration test work with go test
.
#64803
Conversation
test/integration/framework/etcd.go
Outdated
|
||
func setupETCD() { | ||
etcdSetup.Do(func() { | ||
if os.Getenv("RUNFILES_DIR") == "" { |
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.
RUNFILES_DIR
is used when this is run under bazel. This should probably be documented better (at least have a comment), but there's unfortunately not really a better way to pass the path of this dependency, since this is implemented in a library that's used by a bunch of individual go tests. I'd rather not break this functionality.
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.
Thank you, I had no idea about RUNFILES_DIR
. I'll fix this PR to not break that. Testing it with this command.
bazel test //test/integration/scheduler:go_default_test --test_arg=-test.v --test_arg=-test.run=xxx --test_output=all
Also, kubernetes is moving in the direction of not supporting bare |
I understand that this is not the supported path or the way of the future. However, it did seem like low-hanging fruit that would speed up my dev->test cycles. I was hoping that it would be an acceptable change. I'm a bit sad that go build / go test may stop working, because make and bazel are slower and don't integrate as nicely with IDEs. This is clearly not the place for me to plead that case, however. |
if we don't break any existing functionality, I'm fine with this PR. It's worth noting that better IDE support is something that's on the radar for the bazel-go integration, though it's not ready yet. |
Thanks. I confirmed that my fixup patch restores bazel functionality. I tested with this command.
I will squash commits and update the commit message next. |
@ixdy are you the right person to review, now that I've fixed the bazel part? |
test/integration/framework/etcd.go
Outdated
fmt.Fprintf(os.Stderr, installEtcd) | ||
return nil, fmt.Errorf("could not find etcd in PATH: %v", err) | ||
} | ||
// TODO: Pick an unused port. |
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.
this part worries me a little bit. since bazel may run multiple integration tests in parallel, we want to keep the etcd instances separate, hence previously it used a constant "random" port. without any means to ensure this port is unused, this seems like it will cause test flakes.
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 put it back to the way it was, but IMO the previous behavior encodes assumptions about argv[0] that are not obvious. How do I know if argv[0] == 'make' or 'bazel' or 'go'?
I was thinking that the classic, "get a free port from the kernel and then release it" method would be more suitable.
Or I can put the old behavior back.
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 argv[0]
would be the name of the go test that was compiled, e.g. under bazel it might be something like bazel-bin/test/integration/auth/linux_amd64_stripped/go_default_test
.
I'm not sure whether this does the right thing under just go test
though.
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.
though yes, picking an actual free port would be best. the current method of using the test name doesn't help if we run 10 instances of the same test in parallel, e.g. to shake out flakes.
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.
Done. Thanks for the feedback!
/test pull-kubernetes-bazel-test-integration-canary |
/retest |
/retest |
This PR still needs approval. Can anyone from @kubernetes/sig-testing-pr-reviews take a look? |
/test pull-kubernetes-bazel-test-integration-canary |
ack, this fell off my radar, sorry about that. I'll add it to my queue for another look. |
/assign |
/retest |
I am getting the same error on
|
that job is not required and probably broken |
/lgtm |
test/integration/framework/etcd.go
Outdated
if err != nil { | ||
glog.Fatalf("Failed to run etcd: %v", err) | ||
glog.Warningf("error during etcd cleanup: %v", err) |
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've tried running this locally and I'm seeing this constantly warning here with
W0901 00:06:50.067389 15 etcd.go:118] error during etcd cleanup: remove /tmp/integration_test_etcd_data551762727: directory not empty
/retest Review the full test history for this PR. Silence the bot with an |
1 similar comment
/retest Review the full test history for this PR. Silence the bot with an |
/skip |
/retest Review the full test history for this PR. Silence the bot with an |
1 similar comment
/retest Review the full test history for this PR. Silence the bot with an |
The EtcdMain function in integration tests is designed to launch an etcd instance only when running in a bazel test. For non-bazel, we rely on hack/make-rules/test-integration.sh to bring up the etcd instance. This patch fixes the following in EtcdMain: 1. If etcd is not found in ${RUNFILES_DIR} then look in ${PATH}. 2. Try to connect to the etcd started by `make test-integraion`; if it is up, then don't start etcd. 3. Gracefully shut down etcd after tests. 4. Get a port from the OS instead of deriving it from argv[0]. 5. Don't use sync.Once. The benefit of this change is that integration tests work with `go test` as well as `make test-integration` without users needing to do anything special. That makes it much easier to pass go testing flags to tests and integrate with IDEs.
c974d0d
to
117288e
Compare
/lgtm (re-apply lgtm from @ixdy) |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dims, ixdy, misterikkit 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 |
@misterikkit: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
/retest |
What this PR does / why we need it:
The EtcdMain function in integration tests is designed to launch an etcd
instance only when running in a bazel test. For non-bazel, we rely on
hack/make-rules/test-integration.sh to bring up the etcd instance.
This patch fixes the following in EtcdMain:
make test-integraion
; if itis up, then don't start etcd.
The benefit of this change is that integration tests work with
go test
as well as
make test-integration
without users needing to do anythingspecial. That makes it much easier to pass go testing flags to tests and
integrate with IDEs.
Special notes for your reviewer:
I made sure this does not break bazel test.
Release note:
/kind cleanup
/sig testing
@kubernetes/sig-testing-pr-reviews
/cc @kubernetes/sig-contributor-experience-pr-reviews