From 4129b28085ac7b9fa1c84892e2de077e78bab0e3 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Tue, 12 Mar 2019 01:02:48 -0700 Subject: [PATCH] Wait for service to come up before tearing it down (#257) --- aws-js-containers/index.js | 12 +++++++++--- aws-ts-containers/index.ts | 11 +++++++++-- misc/test/examples_test.go | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/aws-js-containers/index.js b/aws-js-containers/index.js index 39cce460b..125af248d 100644 --- a/aws-js-containers/index.js +++ b/aws-js-containers/index.js @@ -1,4 +1,3 @@ -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; diff --git a/aws-ts-containers/index.ts b/aws-ts-containers/index.ts index 9fa9b7c18..9ecfe8216 100644 --- a/aws-ts-containers/index.ts +++ b/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; diff --git a/misc/test/examples_test.go b/misc/test/examples_test.go index b9302e629..0a33dc572 100644 --- a/misc/test/examples_test.go +++ b/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 {