-
Notifications
You must be signed in to change notification settings - Fork 7
/
testing.gradle
237 lines (214 loc) · 7.5 KB
/
testing.gradle
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Testing config
// The path to the default Google service account for the Workspace Manager to run as.
// Created by scripts/write_config.sh
def googleCredentialsFile = "${rootDir}/config/wsm-sa.json"
bootRun {
environment.put("GOOGLE_APPLICATION_CREDENTIALS", "${googleCredentialsFile}")
}
tasks.withType(Test).configureEach {
environment.put("GOOGLE_APPLICATION_CREDENTIALS", "${googleCredentialsFile}")
systemProperty 'spring.profiles.include', 'human-readable-logging'
testLogging {
if (System.getenv('PRINT_STANDARD_STREAMS') == null) {
events = ["passed", "failed", "skipped", "started"]
} else {
events = ["passed", "failed", "skipped", "started", "standard_out", "standard_error"]
}
}
}
// We don't want to use up all the cores on a developer's machine because it locks them out of doing other
// work, but that's not a concern for dedicated CI machines.
def runnerThreads = System.getenv().containsKey("CI") ? Runtime.runtime.availableProcessors() : Runtime.runtime.availableProcessors().intdiv(2)
// Alternatively, if a user specifies the TEST_SINGLE_THREAD env var, we will always restrict tests to a
// single thread. This can be helpful when using a local database.
def singleThread = System.getenv().containsKey("TEST_SINGLE_THREAD")
runnerThreads = singleThread ? 1 : runnerThreads
test {
useJUnitPlatform {
includeTags "unit"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
// For GHA runs, retry failing tests. If 2nd time passes, workflow will still
// fail and oncall will still be notified. This way, oncall dosen't have to
// rerun workflow in GHA.
retry {
// This is set automatically on Github Actions runners, and never set
// otherwise.
if (System.getenv().containsKey("CI")) {
// Max retries per test.
maxRetries = 1
// Max total test failures.
// This is an estimate based on current failure rates, but if more
// than 5 tests fail in a run it's likely a real source of failure
// and we should stop retrying.
maxFailures = 5
}
failOnPassedAfterRetry = true
}
maxParallelForks = runnerThreads
}
// GCP, non-cloud-specific
task unitTest(type: Test) {
useJUnitPlatform {
includeTags "unit"
}
outputs.upToDateWhen { false }
maxParallelForks = runnerThreads
finalizedBy tasks.combinedJaCoCoReport
}
task connectedPlusTest(type: Test) {
environment.put('TEST_ENV', System.getenv("TEST_ENV"))
useJUnitPlatform {
includeTags "connectedPlus"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
// For GHA runs, retry failing tests. If 2nd time passes, workflow will still
// fail and oncall will still be notified. This way, oncall dosen't have to
// rerun workflow in GHA.
retry {
// This is set automatically on Github Actions runners, and never set
// otherwise.
if (System.getenv().containsKey("CI")) {
// Max retries per test.
maxRetries = 1
// Max total test failures.
// This is an estimate based on current failure rates, but if more
// than 5 tests fail in a run it's likely a real source of failure
// and we should stop retrying.
maxFailures = 5
}
failOnPassedAfterRetry = true
}
maxParallelForks = runnerThreads
}
// Use the connected test tag for PR runs.
// No retries; devs can manually rerun
task connectedTest(type: Test) {
environment.put('TEST_ENV', System.getenv("TEST_ENV"))
useJUnitPlatform {
includeTags "connected"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
maxParallelForks = runnerThreads
}
// AZURE
task azureUnitTest(type: Test) {
useJUnitPlatform {
includeTags "azure-unit"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
maxParallelForks = runnerThreads
}
// Use the azureConnected test tag for PR runs.
// No retries; devs can manually rerun
task azureConnectedTest(type: Test) {
useJUnitPlatform {
includeTags "azureConnected"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
maxParallelForks = runnerThreads
}
task azureConnectedPlusTest(type: Test) {
environment.put('TEST_ENV', System.getenv("TEST_ENV"))
useJUnitPlatform {
includeTags "azureConnectedPlus"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
// For GHA runs, retry failing tests. If 2nd time passes, workflow will still
// fail and oncall will still be notified. This way, oncall dosen't have to
// rerun workflow in GHA.
retry {
// This is set automatically on Github Actions runners, and never set
// otherwise.
if (System.getenv().containsKey("CI")) {
// Max retries per test.
maxRetries = 1
// Max total test failures.
// This is an estimate based on current failure rates, but if more
// than 5 tests fail in a run it's likely a real source of failure
// and we should stop retrying.
maxFailures = 5
}
failOnPassedAfterRetry = true
}
maxParallelForks = runnerThreads
}
// AWS
task awsUnitTest(type: Test) {
useJUnitPlatform {
includeTags "aws-unit"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
maxParallelForks = runnerThreads
}
task awsConnectedTest(type: Test) {
useJUnitPlatform {
includeTags "aws-connected"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
maxParallelForks = runnerThreads
}
task awsConnectedPlusTest(type: Test) {
useJUnitPlatform {
includeTags "aws-connected-plus"
}
outputs.upToDateWhen { false }
finalizedBy tasks.combinedJaCoCoReport
// For GHA runs, retry failing tests. If 2nd time passes, workflow will still
// fail and oncall will still be notified. This way, oncall dosen't have to
// rerun workflow in GHA.
retry {
// This is set automatically on Github Actions runners, and never set
// otherwise.
if (System.getenv().containsKey("CI")) {
// Max retries per test.
maxRetries = 1
// Max total test failures.
// This is an estimate based on current failure rates, but if more
// than 5 tests fail in a run it's likely a real source of failure
// and we should stop retrying.
maxFailures = 5
}
failOnPassedAfterRetry = true
}
maxParallelForks = runnerThreads
}
// PACT
task pactTests(type: Test) {
useJUnitPlatform {
includeTags "pact-test"
}
environment.put('pact.rootDir', "$buildDir/pacts")
environment.put('pact.provider.version', "$project.version")
}
def boolean isCiServer = System.getenv().containsKey("CI")
// verify the provider side of pacts WSM has with other services
task verifyPacts(type: Test) {
useJUnitPlatform {
includeTags "pact-verification"
}
testLogging {
events = ["passed", "failed", "skipped", "started", "standard_out"]
}
outputs.upToDateWhen { false }
if (isCiServer) {
systemProperty 'pact.verifier.publishResults', true
}
// to run a local pactbroker, see:
// https://broadworkbench.atlassian.net/wiki/spaces/IRT/pages/2829680649/Contract+Test+Local+Development
if (System.getenv().containsKey('PACT_BROKER_URL')) {
systemProperty 'pactbroker.url', System.getenv('PACT_BROKER_URL')
}
systemProperty 'pact.provider.version', System.getenv('PACT_PROVIDER_VERSION')
systemProperty 'pact.provider.branch', System.getenv('PACT_PROVIDER_BRANCH')
systemProperty 'pactbroker.auth.username', System.getenv('PACT_BROKER_USERNAME')
systemProperty 'pactbroker.auth.password', System.getenv('PACT_BROKER_PASSWORD')
}