Skip to content

Commit

Permalink
Wait for service to come up before tearing it down (pulumi#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Mar 12, 2019
1 parent 954b4c0 commit 705ef3e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
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:https://${listener.endpoint.hostname}`;
// expose some APIs meant for testing purposes.
let api = new awsx.apigateway.API("containers", {
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:https://${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;
16 changes: 15 additions & 1 deletion 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 Expand Up @@ -397,7 +411,7 @@ func assertHTTPResultWithRetry(t *testing.T, output interface{}, maxWait time.Du
for true {
now := time.Now()
resp, err = http.Get(hostname)
if err == nil {
if err == nil && resp.StatusCode == 200 {
break
}
if now.Sub(startTime) >= maxWait {
Expand Down

0 comments on commit 705ef3e

Please sign in to comment.