Skip to content

Commit

Permalink
Create example for testing parallel ECS updates (#1334)
Browse files Browse the repository at this point in the history
Adding an example to test parallel updates to components like ECS
services. Currently component updates are serialized (#1250), but
pulumi/pulumi#7629 fixed that.

I used this test for verifying the changes locally, now that the change
is released we can use this as a regression test
  • Loading branch information
flostadler authored Jul 2, 2024
1 parent 2f165d6 commit f26ad55
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/ecs-parallel/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: ecs-parallel
runtime: nodejs
description: An ECS cluster with a Fargate service
50 changes: 50 additions & 0 deletions examples/ecs-parallel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

const image = "docker.io/memcached:1.6.28"

const clusterA = new aws.ecs.Cluster("cluster-a", {});
const clusterB = new aws.ecs.Cluster("cluster-b", {});

for (let i = 0; i < 5; i++) {
new awsx.ecs.FargateService(`cluster-a-service-${i}`, {
cluster: clusterA.arn,
assignPublicIp: true,
desiredCount: 1,
taskDefinitionArgs: {
container: {
name: `cluster-a-service-${i}`,
image,
cpu: 128,
memory: 512,
essential: true,
},
},
forceNewDeployment: true,
triggers: {
redeployment: Date.now().toString(),
}
});
}

for (let i = 0; i < 5; i++) {
new awsx.ecs.FargateService(`cluster-b-service-${i}`, {
cluster: clusterB.arn,
assignPublicIp: true,
desiredCount: 1,
taskDefinitionArgs: {
container: {
name: `cluster-b-service-${i}`,
image,
cpu: 128,
memory: 512,
essential: true,
},
},
forceNewDeployment: true,
triggers: {
redeployment: Date.now().toString(),
}
});
}
10 changes: 10 additions & 0 deletions examples/ecs-parallel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ecs-parallel",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws": "^6.0.4",
"@pulumi/pulumi": "^3.0.0"
}
}
50 changes: 50 additions & 0 deletions examples/ecs-parallel/step2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

const image = "docker.io/memcached:1.6.29"

const clusterA = new aws.ecs.Cluster("cluster-a", {});
const clusterB = new aws.ecs.Cluster("cluster-b", {});

for (let i = 0; i < 5; i++) {
new awsx.ecs.FargateService(`cluster-a-service-${i}`, {
cluster: clusterA.arn,
assignPublicIp: true,
desiredCount: 1,
taskDefinitionArgs: {
container: {
name: `cluster-a-service-${i}`,
image,
cpu: 128,
memory: 512,
essential: true,
},
},
forceNewDeployment: true,
triggers: {
redeployment: Date.now().toString(),
}
});
}

for (let i = 0; i < 5; i++) {
new awsx.ecs.FargateService(`cluster-b-service-${i}`, {
cluster: clusterB.arn,
assignPublicIp: true,
desiredCount: 1,
taskDefinitionArgs: {
container: {
name: `cluster-b-service-${i}`,
image,
cpu: 128,
memory: 512,
essential: true,
},
},
forceNewDeployment: true,
triggers: {
redeployment: Date.now().toString(),
}
});
}
18 changes: 18 additions & 0 deletions examples/ecs-parallel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}
19 changes: 19 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package examples
import (
"path/filepath"
"testing"
"time"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -201,6 +202,24 @@ func TestVpcMultipleSimilarSubnetSpecArgs(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestAccEcsParallel(t *testing.T) {
maxDuration(15*time.Minute, t, func(t *testing.T) {
test := getNodeJSBaseOptions(t).
With(integration.ProgramTestOptions{
RunUpdateTest: false,
Dir: filepath.Join(getCwd(t), "ecs-parallel"),
EditDirs: []integration.EditDir{
{
Dir: filepath.Join(getCwd(t), "ecs-parallel", "step2"),
Additive: true,
},
},
})

integration.ProgramTest(t, &test)
})
}

func getNodeJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions(t)
nodeBase := base.With(integration.ProgramTestOptions{
Expand Down
16 changes: 16 additions & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
)
Expand Down Expand Up @@ -40,3 +41,18 @@ func getBaseOptions(t *testing.T) integration.ProgramTestOptions {

return baseJS
}

func maxDuration(dur time.Duration, t *testing.T, test func(t *testing.T)) {
t.Helper()
timeout := time.After(dur)
done := make(chan bool)
go func() {
test(t)
done <- true
}()
select {
case <-timeout:
t.Fatalf("Test timed out after %v", dur)
case <-done:
}
}

0 comments on commit f26ad55

Please sign in to comment.