Skip to content

Commit a370f6e

Browse files
author
Rui Hu
committed
cloud: allow parallel running of cloud unit tests
Append a random uint64 in the paths of cloud unit tests to prevent parallel executions from interfering with each other. This is necessary since these tests now run for all release branches and can run in parallel. Fixes: cockroachdb#107137 Fixes: cockroachdb#107139 Release note: None
1 parent 43d5804 commit a370f6e

File tree

4 files changed

+73
-38
lines changed

4 files changed

+73
-38
lines changed

pkg/cloud/amazon/s3_storage_test.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ func TestPutS3(t *testing.T) {
7979

8080
ctx := context.Background()
8181
user := username.RootUserName()
82+
testID := cloudtestutils.NewTestID()
83+
8284
t.Run("auth-empty-no-cred", func(t *testing.T) {
83-
_, err := cloud.ExternalStorageFromURI(ctx, fmt.Sprintf("s3://%s/%s", bucket,
84-
"backup-test-default"), base.ExternalIODirConfig{}, testSettings,
85+
_, err := cloud.ExternalStorageFromURI(ctx, fmt.Sprintf("s3://%s/%s-%d", bucket,
86+
"backup-test-default", testID), base.ExternalIODirConfig{}, testSettings,
8587
blobs.TestEmptyBlobClientFactory, user,
8688
nil, /* ie */
8789
nil, /* ief */
@@ -109,15 +111,15 @@ func TestPutS3(t *testing.T) {
109111
}
110112

111113
cloudtestutils.CheckExportStore(t, fmt.Sprintf(
112-
"s3://%s/%s?%s=%s",
113-
bucket, "backup-test-default",
114+
"s3://%s/%s-%d?%s=%s",
115+
bucket, "backup-test-default", testID,
114116
cloud.AuthParam, cloud.AuthParamImplicit,
115117
), false, user,
116118
nil, /* db */
117119
testSettings)
118120
})
119121
t.Run("auth-specified", func(t *testing.T) {
120-
uri := S3URI(bucket, "backup-test",
122+
uri := S3URI(bucket, fmt.Sprintf("backup-test-%d", testID),
121123
&cloudpb.ExternalStorage_S3{AccessKey: creds.AccessKeyID, Secret: creds.SecretAccessKey, Region: "us-east-1"},
122124
)
123125
cloudtestutils.CheckExportStore(
@@ -142,8 +144,8 @@ func TestPutS3(t *testing.T) {
142144
}
143145

144146
cloudtestutils.CheckExportStore(t, fmt.Sprintf(
145-
"s3://%s/%s?%s=%s&%s=%s",
146-
bucket, "backup-test-sse-256",
147+
"s3://%s/%s-%d?%s=%s&%s=%s",
148+
bucket, "backup-test-sse-256", testID,
147149
cloud.AuthParam, cloud.AuthParamImplicit, AWSServerSideEncryptionMode,
148150
"AES256",
149151
),
@@ -158,8 +160,8 @@ func TestPutS3(t *testing.T) {
158160
skip.IgnoreLint(t, "AWS_KMS_KEY_ARN env var must be set")
159161
}
160162
cloudtestutils.CheckExportStore(t, fmt.Sprintf(
161-
"s3://%s/%s?%s=%s&%s=%s&%s=%s",
162-
bucket, "backup-test-sse-kms",
163+
"s3://%s/%s-%d?%s=%s&%s=%s&%s=%s",
164+
bucket, "backup-test-sse-kms", testID,
163165
cloud.AuthParam, cloud.AuthParamImplicit, AWSServerSideEncryptionMode,
164166
"aws:kms", AWSServerSideEncryptionKMSID, v,
165167
),
@@ -218,6 +220,8 @@ func TestPutS3AssumeRole(t *testing.T) {
218220
}
219221

220222
testSettings := cluster.MakeTestingClusterSettings()
223+
testID := cloudtestutils.NewTestID()
224+
testPath := fmt.Sprintf("backup-test-%d", testID)
221225

222226
user := username.RootUserName()
223227

@@ -232,7 +236,7 @@ func TestPutS3AssumeRole(t *testing.T) {
232236
skip.IgnoreLintf(t, "we only run this test if a default role exists, "+
233237
"refer to https://docs.aws.com/cli/latest/userguide/cli-configure-role.html: %s", err)
234238
}
235-
uri := S3URI(bucket, "backup-test",
239+
uri := S3URI(bucket, testPath,
236240
&cloudpb.ExternalStorage_S3{Auth: cloud.AuthParamImplicit, RoleARN: roleArn, Region: "us-east-1"},
237241
)
238242
cloudtestutils.CheckExportStore(
@@ -244,7 +248,7 @@ func TestPutS3AssumeRole(t *testing.T) {
244248
})
245249

246250
t.Run("auth-specified", func(t *testing.T) {
247-
uri := S3URI(bucket, "backup-test",
251+
uri := S3URI(bucket, testPath,
248252
&cloudpb.ExternalStorage_S3{Auth: cloud.AuthParamSpecified, RoleARN: roleArn, AccessKey: creds.AccessKeyID, Secret: creds.SecretAccessKey, Region: "us-east-1"},
249253
)
250254
cloudtestutils.CheckExportStore(
@@ -274,7 +278,7 @@ func TestPutS3AssumeRole(t *testing.T) {
274278
t.Run(tc.auth, func(t *testing.T) {
275279
// First verify that none of the individual roles in the chain can be used to access the storage.
276280
for _, p := range providerChain {
277-
roleURI := S3URI(bucket, "backup-test",
281+
roleURI := S3URI(bucket, testPath,
278282
&cloudpb.ExternalStorage_S3{
279283
Auth: tc.auth,
280284
AssumeRoleProvider: p,
@@ -296,7 +300,7 @@ func TestPutS3AssumeRole(t *testing.T) {
296300
delegatesWithoutID = append(delegatesWithoutID, cloudpb.ExternalStorage_AssumeRoleProvider{Role: p.Role})
297301
}
298302

299-
uri := S3URI(bucket, "backup-test",
303+
uri := S3URI(bucket, testPath,
300304
&cloudpb.ExternalStorage_S3{
301305
Auth: tc.auth,
302306
AssumeRoleProvider: roleWithoutID,
@@ -311,7 +315,7 @@ func TestPutS3AssumeRole(t *testing.T) {
311315
)
312316

313317
// Finally, check that the chain of roles can be used to access the storage.
314-
uri = S3URI(bucket, "backup-test",
318+
uri = S3URI(bucket, testPath,
315319
&cloudpb.ExternalStorage_S3{
316320
Auth: tc.auth,
317321
AssumeRoleProvider: providerChain[len(providerChain)-1],
@@ -352,11 +356,12 @@ func TestPutS3Endpoint(t *testing.T) {
352356
skip.IgnoreLint(t, "AWS_S3_BUCKET env var must be set")
353357
}
354358
user := username.RootUserName()
359+
testID := cloudtestutils.NewTestID()
355360

356361
u := url.URL{
357362
Scheme: "s3",
358363
Host: bucket,
359-
Path: "backup-test",
364+
Path: fmt.Sprintf("backup-test-%d", testID),
360365
RawQuery: q.Encode(),
361366
}
362367

pkg/cloud/azure/azure_storage_test.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package azure
1313
import (
1414
"context"
1515
"encoding/base64"
16+
"fmt"
1617
"net/url"
1718
"os"
1819
"path"
@@ -109,12 +110,16 @@ func TestAzure(t *testing.T) {
109110
return
110111
}
111112
testSettings := cluster.MakeTestingClusterSettings()
112-
cloudtestutils.CheckExportStore(t, cfg.filePath("backup-test"),
113+
testID := cloudtestutils.NewTestID()
114+
testPath := fmt.Sprintf("backup-test-%d", testID)
115+
testListPath := fmt.Sprintf("listing-test-%d", testID)
116+
117+
cloudtestutils.CheckExportStore(t, cfg.filePath(testPath),
113118
false, username.RootUserName(),
114119
nil, /* db */
115120
testSettings,
116121
)
117-
cloudtestutils.CheckListFiles(t, cfg.filePath("listing-test"),
122+
cloudtestutils.CheckListFiles(t, cfg.filePath(testListPath),
118123
username.RootUserName(),
119124
nil, /* db */
120125
testSettings,
@@ -176,21 +181,23 @@ func TestAntagonisticAzureRead(t *testing.T) {
176181
return
177182
}
178183
testSettings := cluster.MakeTestingClusterSettings()
184+
testID := cloudtestutils.NewTestID()
185+
antagonistPath := fmt.Sprintf("antagonistic-read-%d", testID)
179186

180187
conf, err := cloud.ExternalStorageConfFromURI(
181-
cfg.filePath("antagonistic-read"), username.RootUserName())
188+
cfg.filePath(antagonistPath), username.RootUserName())
182189
require.NoError(t, err)
183190

184191
cloudtestutils.CheckAntagonisticRead(t, conf, testSettings)
185192

186193
clientAuthConf, err := cloud.ExternalStorageConfFromURI(
187-
cfg.filePathClientAuth("antagonistic-read"), username.RootUserName())
194+
cfg.filePathClientAuth(antagonistPath), username.RootUserName())
188195
require.NoError(t, err)
189196

190197
cloudtestutils.CheckAntagonisticRead(t, clientAuthConf, testSettings)
191198

192199
implicitAuthConf, err := cloud.ExternalStorageConfFromURI(
193-
cfg.filePathImplicitAuth("antagonistic-read"), username.RootUserName())
200+
cfg.filePathImplicitAuth(antagonistPath), username.RootUserName())
194201
require.NoError(t, err)
195202

196203
cloudtestutils.CheckAntagonisticRead(t, implicitAuthConf, testSettings)
@@ -277,11 +284,15 @@ func TestAzureStorageFileImplicitAuth(t *testing.T) {
277284
return
278285
}
279286
testSettings := cluster.MakeTestingClusterSettings()
287+
testID := cloudtestutils.NewTestID()
280288

281289
cleanup := envutil.TestSetEnv(t, "AZURE_CLIENT_ID", "")
282290
defer cleanup()
283291

284-
cloudtestutils.CheckNoPermission(t, cfg.filePathImplicitAuth("backup-test"), username.RootUserName(),
292+
testPath := fmt.Sprintf("backup-test-%d", testID)
293+
testListPath := fmt.Sprintf("listing-test-%d", testID)
294+
295+
cloudtestutils.CheckNoPermission(t, cfg.filePathImplicitAuth(testPath), username.RootUserName(),
285296
nil /*db*/, testSettings)
286297

287298
tmpDir, cleanup2 := testutils.TempDir(t)
@@ -293,12 +304,12 @@ func TestAzureStorageFileImplicitAuth(t *testing.T) {
293304
cleanup3 := envutil.TestSetEnv(t, "COCKROACH_AZURE_APPLICATION_CREDENTIALS_FILE", credFile)
294305
defer cleanup3()
295306

296-
cloudtestutils.CheckExportStore(t, cfg.filePathImplicitAuth("backup-test"),
307+
cloudtestutils.CheckExportStore(t, cfg.filePathImplicitAuth(testPath),
297308
false, username.RootUserName(),
298309
nil, /* db */
299310
testSettings,
300311
)
301-
cloudtestutils.CheckListFiles(t, cfg.filePathImplicitAuth("listing-test"),
312+
cloudtestutils.CheckListFiles(t, cfg.filePathImplicitAuth(testListPath),
302313
username.RootUserName(),
303314
nil, /* db */
304315
testSettings,

pkg/cloud/cloudtestutils/cloud_test_helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,8 @@ func IsImplicitAuthConfigured() bool {
591591
credentials := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
592592
return credentials != ""
593593
}
594+
595+
func NewTestID() uint64 {
596+
rng, _ := randutil.NewTestRand()
597+
return rng.Uint64()
598+
}

pkg/cloud/gcp/gcs_storage_test.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ func TestPutGoogleCloud(t *testing.T) {
4545

4646
user := username.RootUserName()
4747
testSettings := cluster.MakeTestingClusterSettings()
48+
testID := cloudtestutils.NewTestID()
4849

4950
testutils.RunTrueAndFalse(t, "auth-specified-with-auth-param", func(t *testing.T, specified bool) {
5051
credentials := os.Getenv("GOOGLE_CREDENTIALS_JSON")
5152
if credentials == "" {
5253
skip.IgnoreLint(t, "GOOGLE_CREDENTIALS_JSON env var must be set")
5354
}
5455
encoded := base64.StdEncoding.EncodeToString([]byte(credentials))
55-
uri := fmt.Sprintf("gs://%s/%s?%s=%s",
56+
uri := fmt.Sprintf("gs://%s/%s-%d?%s=%s",
5657
bucket,
5758
"backup-test-specified",
59+
testID,
5860
CredentialsParam,
5961
url.QueryEscape(encoded),
6062
)
@@ -69,9 +71,10 @@ func TestPutGoogleCloud(t *testing.T) {
6971
nil, /* db */
7072
testSettings,
7173
)
72-
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s/%s?%s=%s&%s=%s",
74+
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s-%d/%s?%s=%s&%s=%s",
7375
bucket,
7476
"backup-test-specified",
77+
testID,
7578
"listing-test",
7679
cloud.AuthParam,
7780
cloud.AuthParamSpecified,
@@ -89,15 +92,16 @@ func TestPutGoogleCloud(t *testing.T) {
8992

9093
cloudtestutils.CheckExportStore(
9194
t,
92-
fmt.Sprintf("gs://%s/%s?%s=%s", bucket, "backup-test-implicit",
95+
fmt.Sprintf("gs://%s/%s-%d?%s=%s", bucket, "backup-test-implicit", testID,
9396
cloud.AuthParam, cloud.AuthParamImplicit),
9497
false,
9598
user,
9699
nil, /* db */
97100
testSettings)
98-
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s/%s?%s=%s",
101+
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s-%d/%s?%s=%s",
99102
bucket,
100103
"backup-test-implicit",
104+
testID,
101105
"listing-test",
102106
cloud.AuthParam,
103107
cloud.AuthParamImplicit,
@@ -121,9 +125,10 @@ func TestPutGoogleCloud(t *testing.T) {
121125
token, err := ts.Token()
122126
require.NoError(t, err, "getting token")
123127

124-
uri := fmt.Sprintf("gs://%s/%s?%s=%s",
128+
uri := fmt.Sprintf("gs://%s/%s-%d?%s=%s",
125129
bucket,
126130
"backup-test-specified",
131+
testID,
127132
BearerTokenParam,
128133
token.AccessToken,
129134
)
@@ -135,9 +140,10 @@ func TestPutGoogleCloud(t *testing.T) {
135140
user,
136141
nil, /* db */
137142
testSettings)
138-
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s/%s?%s=%s&%s=%s",
143+
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s-%d/%s?%s=%s&%s=%s",
139144
bucket,
140145
"backup-test-specified",
146+
testID,
141147
"listing-test",
142148
cloud.AuthParam,
143149
cloud.AuthParamSpecified,
@@ -163,6 +169,8 @@ func TestGCSAssumeRole(t *testing.T) {
163169
skip.IgnoreLint(t, "ASSUME_SERVICE_ACCOUNT env var must be set")
164170
}
165171

172+
testID := cloudtestutils.NewTestID()
173+
166174
t.Run("specified", func(t *testing.T) {
167175
credentials := os.Getenv("GOOGLE_CREDENTIALS_JSON")
168176
if credentials == "" {
@@ -172,17 +180,18 @@ func TestGCSAssumeRole(t *testing.T) {
172180

173181
// Verify that specified permissions with the credentials do not give us
174182
// access to the bucket.
175-
cloudtestutils.CheckNoPermission(t, fmt.Sprintf("gs://%s/%s?%s=%s", limitedBucket, "backup-test-assume-role",
183+
cloudtestutils.CheckNoPermission(t, fmt.Sprintf("gs://%s/%s-%d?%s=%s", limitedBucket, "backup-test-assume-role", testID,
176184
CredentialsParam, url.QueryEscape(encoded)), user,
177185
nil, /* db */
178186
testSettings,
179187
)
180188

181189
cloudtestutils.CheckExportStore(
182190
t,
183-
fmt.Sprintf("gs://%s/%s?%s=%s&%s=%s&%s=%s",
191+
fmt.Sprintf("gs://%s/%s-%d?%s=%s&%s=%s&%s=%s",
184192
limitedBucket,
185193
"backup-test-assume-role",
194+
testID,
186195
cloud.AuthParam,
187196
cloud.AuthParamSpecified,
188197
AssumeRoleParam,
@@ -192,9 +201,10 @@ func TestGCSAssumeRole(t *testing.T) {
192201
nil, /* db */
193202
testSettings,
194203
)
195-
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s/%s?%s=%s&%s=%s&%s=%s",
204+
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s-%d/%s?%s=%s&%s=%s&%s=%s",
196205
limitedBucket,
197206
"backup-test-assume-role",
207+
testID,
198208
"listing-test",
199209
cloud.AuthParam,
200210
cloud.AuthParamSpecified,
@@ -215,20 +225,21 @@ func TestGCSAssumeRole(t *testing.T) {
215225

216226
// Verify that implicit permissions with the credentials do not give us
217227
// access to the bucket.
218-
cloudtestutils.CheckNoPermission(t, fmt.Sprintf("gs://%s/%s?%s=%s", limitedBucket, "backup-test-assume-role",
228+
cloudtestutils.CheckNoPermission(t, fmt.Sprintf("gs://%s/%s-%d?%s=%s", limitedBucket, "backup-test-assume-role", testID,
219229
cloud.AuthParam, cloud.AuthParamImplicit), user,
220230
nil, /* db */
221231
testSettings,
222232
)
223233

224-
cloudtestutils.CheckExportStore(t, fmt.Sprintf("gs://%s/%s?%s=%s&%s=%s", limitedBucket, "backup-test-assume-role",
234+
cloudtestutils.CheckExportStore(t, fmt.Sprintf("gs://%s/%s-%d?%s=%s&%s=%s", limitedBucket, "backup-test-assume-role", testID,
225235
cloud.AuthParam, cloud.AuthParamImplicit, AssumeRoleParam, assumedAccount), false, user,
226236
nil, /* db */
227237
testSettings,
228238
)
229-
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s/%s?%s=%s&%s=%s",
239+
cloudtestutils.CheckListFiles(t, fmt.Sprintf("gs://%s/%s-%d/%s?%s=%s&%s=%s",
230240
limitedBucket,
231241
"backup-test-assume-role",
242+
testID,
232243
"listing-test",
233244
cloud.AuthParam,
234245
cloud.AuthParamImplicit,
@@ -270,9 +281,10 @@ func TestGCSAssumeRole(t *testing.T) {
270281
// to access the storage.
271282
for _, role := range roleChain {
272283
q.Set(AssumeRoleParam, role)
273-
roleURI := fmt.Sprintf("gs://%s/%s/%s?%s",
284+
roleURI := fmt.Sprintf("gs://%s/%s-%d/%s?%s",
274285
limitedBucket,
275286
"backup-test-assume-role",
287+
testID,
276288
"listing-test",
277289
q.Encode(),
278290
)
@@ -284,9 +296,10 @@ func TestGCSAssumeRole(t *testing.T) {
284296

285297
// Finally, check that the chain of roles can be used to access the storage.
286298
q.Set(AssumeRoleParam, roleChainStr)
287-
uri := fmt.Sprintf("gs://%s/%s/%s?%s",
299+
uri := fmt.Sprintf("gs://%s/%s-%d/%s?%s",
288300
limitedBucket,
289301
"backup-test-assume-role",
302+
testID,
290303
"listing-test",
291304
q.Encode(),
292305
)
@@ -454,13 +467,14 @@ func TestReadFileAtReturnsSize(t *testing.T) {
454467
skip.IgnoreLint(t, "GOOGLE_BUCKET env var must be set")
455468
}
456469

470+
testID := cloudtestutils.NewTestID()
457471
user := username.RootUserName()
458472
ctx := context.Background()
459473
testSettings := cluster.MakeTestingClusterSettings()
460474
file := "testfile"
461475
data := []byte("hello world")
462476

463-
gsURI := fmt.Sprintf("gs://%s/%s?AUTH=implicit", bucket, "read-file-at-returns-size")
477+
gsURI := fmt.Sprintf("gs://%s/%s-%d?AUTH=implicit", bucket, "read-file-at-returns-size", testID)
464478
conf, err := cloud.ExternalStorageConfFromURI(gsURI, user)
465479
require.NoError(t, err)
466480
args := cloud.ExternalStorageContext{

0 commit comments

Comments
 (0)