forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance_test.go
191 lines (173 loc) · 6.13 KB
/
performance_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// +build Performance all
package test
import (
"fmt"
"log"
"os"
"path"
"testing"
"time"
"github.com/pulumi/pulumi-trace-tool/traces"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/assert"
)
func bench(name, provider, runtime, lang string) traces.Benchmark {
b := traces.NewBenchmark(name)
b.Provider = provider
b.Runtime = runtime
b.Language = lang
b.Repository = "pulumi/examples"
return b
}
func TestAccAwsGoS3Folder(t *testing.T) {
benchmark := bench("aws-go-s3-folder", "aws", "go", "go")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
maxWait := 10 * time.Minute
endpoint := stack.Outputs["websiteUrl"].(string)
assertHTTPResultWithRetry(t, endpoint, nil, maxWait, func(body string) bool {
return assert.Contains(t, body, "Hello, world!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
func TestAccAwsCsS3Folder(t *testing.T) {
benchmark := bench("aws-cs-s3-folder", "aws", "dotnet", "csharp")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
maxWait := 10 * time.Minute
endpoint := stack.Outputs["Endpoint"].(string)
assertHTTPResultWithRetry(t, endpoint, nil, maxWait, func(body string) bool {
return assert.Contains(t, body, "Hello, world!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
func TestAccAwsFsS3Folder(t *testing.T) {
benchmark := bench("aws-fs-s3-folder", "aws", "dotnet", "fsharp")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
maxWait := 10 * time.Minute
endpoint := stack.Outputs["endpoint"].(string)
assertHTTPResultWithRetry(t, endpoint, nil, maxWait, func(body string) bool {
return assert.Contains(t, body, "Hello, world!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
func TestAccAwsJsS3Folder(t *testing.T) {
benchmark := bench("aws-js-s3-folder", "aws", "nodejs", "js")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, "http:https://"+stack.Outputs["websiteUrl"].(string), nil, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
func TestAccAwsTsS3Folder(t *testing.T) {
benchmark := bench("aws-ts-s3-folder", "aws", "nodejs", "ts")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, "http:https://"+stack.Outputs["websiteUrl"].(string), nil, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
func TestAccAwsPyS3Folder(t *testing.T) {
benchmark := bench("aws-py-s3-folder", "aws", "python", "python")
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "..", benchmark.Name),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assertHTTPResult(t, "http:https://"+stack.Outputs["website_url"].(string), nil, func(body string) bool {
return assert.Contains(t, body, "Hello, Pulumi!")
})
},
}
test := getAWSBase(t).With(opts).With(benchmark.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
type manyResourcesConfig struct {
folder string
bench traces.Benchmark
resources int
payloadBytes int
}
func TestManyResources(t *testing.T) {
var configurations []manyResourcesConfig
for _, resources := range []int{64, 128, 256} {
confs := []manyResourcesConfig{
{
folder: "go-many-resources",
bench: bench(fmt.Sprintf("go-many-resources-%d", resources), "", "go", "go"),
resources: resources,
payloadBytes: 8,
},
{
folder: "cs-many-resources",
bench: bench(fmt.Sprintf("cs-many-resources-%d", resources), "", "dotnet", "csharp"),
resources: resources,
payloadBytes: 8,
},
{
folder: "ts-many-resources",
bench: bench(fmt.Sprintf("ts-many-resources-%d", resources), "", "nodejs", "typescript"),
resources: resources,
payloadBytes: 8,
},
{
folder: "py-many-resources",
bench: bench(fmt.Sprintf("py-many-resources-%d", resources), "", "python", "python"),
resources: resources,
payloadBytes: 8,
},
}
configurations = append(configurations, confs...)
}
check := func(t *testing.T, cfg manyResourcesConfig) {
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "benchmarks", cfg.folder),
Config: map[string]string{
"resource_count": fmt.Sprintf("%d", cfg.resources),
"resource_payload_bytes": fmt.Sprintf("%d", cfg.payloadBytes),
},
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assert.Equal(t, float64(cfg.resources), stack.Outputs["ResourceCount"])
assert.Equal(t, float64(cfg.payloadBytes), stack.Outputs["ResourcePayloadBytes"])
},
}
test := getBaseOptions(t).With(opts).With(cfg.bench.ProgramTestOptions())
integration.ProgramTest(t, &test)
}
for _, cfg := range configurations {
t.Run(cfg.bench.Name, func(t *testing.T) {
check(t, cfg)
})
}
}
func TestMain(m *testing.M) {
code := m.Run()
// If tracing is enabled, after all tests run with tracing,
// compute metrics on the entire set.
err := traces.ComputeMetrics()
if err != nil {
log.Fatal(err)
}
os.Exit(code)
}