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

Wait for service to come up before tearing it down #257

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions aws-js-containers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const pulumi = require("@pulumi/pulumi");
const awsx = require("@pulumi/awsx");

let cluster = new awsx.ecs.Cluster("example", { });
Expand All @@ -17,5 +16,12 @@ let service = new awsx.ecs.FargateService("nginx", {
},
});

// export just the hostname property of the container frontend
exports.hostname = pulumi.interpolate `http://${listener.endpoint.hostname}`;
// expose some APIs meant for testing purposes.
let api = new awsx.apigateway.API("containers", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Unfortunately - I don't think we should put anything in the examples that is overtly for testing purposes. The examples really do need to stay focused on being user-facing examples. If we can find ways to make them more testable while still being great purely as examples - we should do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha... the main issue here is one of timing. it looks like there's an issue with terraform where they can end up doing things badly if destroy happens quickly after create: hashicorp/terraform#2902

They identify a potential problem being that the service should not be destroyed here before rolepolicies it depends on are destroyed. However, in our case, becaues we're using awsvpc we don't pass along roles/policies to our service.

This was a attempt at a cludgy workaround by at least having some validation wait until the service was up and running properly before tearing it down. I'm not quite sure the best way to actually handle this. Note: i don't really mind having the API here. It doesn't seem unreasonable given that the example if launching an nginx instance and pointing to some html.

routes: [{
path: "/nginx",
target: listener,
}],
});

exports.frontendURL = api.url;
11 changes: 9 additions & 2 deletions aws-ts-containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ let service = new awsx.ecs.FargateService("nginx", {
},
});

// export just the hostname property of the container frontend
export const hostname = pulumi.interpolate `http://${listener.endpoint.hostname}`;
// expose some APIs meant for testing purposes.
const api = new awsx.apigateway.API("containers", {
routes: [{
path: "/nginx",
target: listener,
}],
});

export let frontendURL = api.url;
14 changes: 14 additions & 0 deletions misc/test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func TestExamples(t *testing.T) {
Config: map[string]string{
"aws:region": awsRegion,
},
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
maxWait := 10 * time.Minute
endpoint := stack.Outputs["frontendURL"].(string)
assertHTTPResultWithRetry(t, endpoint+"nginx", maxWait, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}),
base.With(integration.ProgramTestOptions{
Dir: path.Join(cwd, "..", "..", "aws-js-s3-folder"),
Expand Down Expand Up @@ -130,6 +137,13 @@ func TestExamples(t *testing.T) {
Config: map[string]string{
"aws:region": awsRegion,
},
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
maxWait := 10 * time.Minute
endpoint := stack.Outputs["frontendURL"].(string)
assertHTTPResultWithRetry(t, endpoint+"nginx", maxWait, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}),
base.With(integration.ProgramTestOptions{
Dir: path.Join(cwd, "..", "..", "aws-ts-pulumi-webhooks"),
Expand Down