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

Refactor test stages into functions. #2164

Merged
merged 6 commits into from
Oct 17, 2018

Conversation

josephburnett
Copy link
Contributor

Proposed Changes

  • Refactor autoscale E2E into stages in preparation for adding more tests.

E.g. the next test I will create will be something like:

	ctx := setup(t)
	defer tearDown(ctx)
	stopChan := DiagnoseMeEvery(15*time.Second, ctx.clients, ctx.logger)
	defer close(stopChan)

	assertScaleDown(ctx)
	bounceController(ctx)
	assertScaleUp(ctx)

Release Note

NONE

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 5, 2018
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@josephburnett: 2 warnings.

In response to this:

Proposed Changes

  • Refactor autoscale E2E into stages in preparation for adding more tests.

E.g. the next test I will create will be something like:

  ctx := setup(t)
  defer tearDown(ctx)
  stopChan := DiagnoseMeEvery(15*time.Second, ctx.clients, ctx.logger)
  defer close(stopChan)

  assertScaleDown(ctx)
  bounceController(ctx)
  assertScaleUp(ctx)

Release Note

NONE

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.

@josephburnett josephburnett added this to the Scaling: Robust E2E Autoscaling Tests milestone Oct 5, 2018
@josephburnett josephburnett requested a review from adrcunha October 5, 2018 17:52
@josephburnett
Copy link
Contributor Author

/lint

Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@josephburnett: 0 warnings.

In response to this:

/lint

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.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Few comments 👼

logger.Infof("All %d requests succeeded.", totalRequests)
return nil
type testContext struct {
t *testing.T
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge fan of having testing.T inside the testContext… Especially as it doesn't seem to be used in the assert function (doing a logger.Fatal instead)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should be doing ctx.t.Fatalf instead to fail the test.

return nil
}

func TestAutoscaleUpDownUp(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

	ctx := setup(t)
	stopChan := DiagnoseMeEvery(15*time.Second, ctx.clients, ctx.logger)
	defer close(stopChan)
	defer tearDown(t, ctx)
 	assertScaleUp(t, ctx)
	assertScaleDown(t, ctx)
	assertScaleUp(t, ctx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put the defer tearDown after the setup in case the DiagnoseMeEvery call panics.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/approve

if err != nil {
return fmt.Errorf("error creating spoofing client: %v", err)
}
// ctx.logger.Infof( /* DO NOT SUBMIT */ "sending request to %v", fmt.Sprintf("http://%s", ctx.domain))
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

func setup(t *testing.T, logger *logging.BaseLogger) *test.Clients {
func setup(t *testing.T) *testContext {
//add test case specific name to its own logger
logger := logging.GetContextLogger("TestAutoscaleUpDownUp")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you meant to use t.Name() here, instead of the hardcoded test name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@adrcunha
Copy link
Contributor

You have a conflict that needs to be resolved, so my /lgtm won't do any good. Ping me once you get it done and I'll /lgtm.

@adrcunha
Copy link
Contributor

Build errors :(

W1017 16:59:50.535] # github.com/knative/serving/test/e2e
W1017 16:59:50.535] test/e2e/autoscale_test.go:124:1: missing return at end of function
W1017 16:59:50.535] test/e2e/autoscale_test.go:209:24: not enough arguments in call to generateTraffic
W1017 16:59:50.536] 	have (*testContext, number, time.Duration)
W1017 16:59:50.536] 	want (*"github.com/knative/serving/test".Clients, *logging.BaseLogger, int, time.Duration, string)
W1017 16:59:50.536] test/e2e/autoscale_test.go:258:12: undefined: group
W1017 16:59:50.536] test/e2e/autoscale_test.go:259:3: too many arguments to return
W1017 16:59:50.536] 	have (error)
W1017 16:59:50.537] 	want ()
W1017 16:59:50.537] test/e2e/autoscale_test.go:262:5: undefined: successfulRequests
W1017 16:59:50.537] test/e2e/autoscale_test.go:262:27: undefined: totalRequests
W1017 16:59:50.537] test/e2e/autoscale_test.go:263:3: too many arguments to return
W1017 16:59:50.537] 	have (error)
W1017 16:59:50.538] 	want ()
W1017 16:59:50.538] test/e2e/autoscale_test.go:264:4: undefined: successfulRequests
W1017 16:59:50.538] test/e2e/autoscale_test.go:264:24: undefined: totalRequests
W1017 16:59:50.538] test/e2e/autoscale_test.go:267:49: undefined: totalRequests
W1017 16:59:50.538] test/e2e/autoscale_test.go:267:49: too many errors

@adrcunha
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2018
@adrcunha
Copy link
Contributor

/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrcunha, josephburnett, vdemeester

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2018
@knative-prow-robot knative-prow-robot merged commit d841ed1 into knative:master Oct 17, 2018
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. lgtm Indicates that a PR is ready to be merged. 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.

5 participants