Wait for service to come up before tearing it down
MODIFY
aws-js-containers/index.js
aws-js-containers/index.js
-const pulumi = require("@pulumi/pulumi");
const awsx = require("@pulumi/awsx");
let cluster = new awsx.ecs.Cluster("example", { });
@@ -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", {
+ routes: [{
+ path: "/nginx",
+ target: listener,
+ }],
+});
+
+exports.frontendURL = api.url;

MODIFY
aws-ts-containers/index.ts
aws-ts-containers/index.ts
@@ -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;

MODIFY
misc/test/examples_test.go
misc/test/examples_test.go
@@ -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"),
@@ -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"),
@@ -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 {

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