Skip to content

Commit d99ce46

Browse files
authored
chore(storage): use context value to skip transport tests (#6662)
Introduce the `skipTransportTestKey` `context.Value` key in order to skip specific integration tests for one of the two supported transports. The test uses one of the two helpers to create the proper context, either `skipGRPC` or `skipHTTP`, combined with the reason for skipping as the value, and the test runner will skip that transport if it is present in the context supplied to it, logging the reason with the Skip. Refactor and skip two tests, BucketLifecycle which is broken for gRPC atm, and MultiMessageWriteGRPC which is just meant to exercise edge cases in the gRPC Writer implementation.
1 parent dc02bca commit d99ce46

1 file changed

Lines changed: 92 additions & 89 deletions

File tree

storage/integration_test.go

Lines changed: 92 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import (
6363
"google.golang.org/grpc/codes"
6464
)
6565

66+
type skipTransportTestKey string
67+
6668
const (
6769
testPrefix = "go-integration-test"
6870
replayFilename = "storage.replay"
@@ -258,6 +260,10 @@ func multiTransportTest(ctx context.Context, t *testing.T, test func(*testing.T,
258260
t.Run(transport, func(t *testing.T) {
259261
defer client.Close()
260262

263+
if reason := ctx.Value(skipTransportTestKey(transport)); reason != nil {
264+
t.Skip("transport", fmt.Sprintf("%q", transport), "explicitly skipped:", reason)
265+
}
266+
261267
bucket := bucketName
262268
var prefix string
263269
if transport == "grpc" {
@@ -470,50 +476,49 @@ func TestIntegration_BucketCreateDelete(t *testing.T) {
470476
}
471477

472478
func TestIntegration_BucketLifecycle(t *testing.T) {
473-
ctx := context.Background()
474-
client := testConfig(ctx, t)
475-
defer client.Close()
476-
h := testHelper{t}
479+
multiTransportTest(skipGRPC("b/245997450"), t, func(t *testing.T, ctx context.Context, _ string, prefix string, client *Client) {
480+
h := testHelper{t}
477481

478-
wantLifecycle := Lifecycle{
479-
Rules: []LifecycleRule{
480-
{
481-
Action: LifecycleAction{Type: AbortIncompleteMPUAction},
482-
Condition: LifecycleCondition{AgeInDays: 30},
483-
},
484-
{
485-
Action: LifecycleAction{Type: DeleteAction},
486-
Condition: LifecycleCondition{AllObjects: true},
482+
wantLifecycle := Lifecycle{
483+
Rules: []LifecycleRule{
484+
{
485+
Action: LifecycleAction{Type: AbortIncompleteMPUAction},
486+
Condition: LifecycleCondition{AgeInDays: 30},
487+
},
488+
{
489+
Action: LifecycleAction{Type: DeleteAction},
490+
Condition: LifecycleCondition{AllObjects: true},
491+
},
487492
},
488-
},
489-
}
493+
}
490494

491-
bucket := client.Bucket(uidSpace.New())
495+
bucket := client.Bucket(prefix + uidSpace.New())
492496

493-
// Create bucket with lifecycle rules
494-
bucket.Create(ctx, testutil.ProjID(), &BucketAttrs{
495-
Lifecycle: wantLifecycle,
496-
})
497-
defer h.mustDeleteBucket(bucket)
497+
// Create bucket with lifecycle rules
498+
h.mustCreate(bucket, testutil.ProjID(), &BucketAttrs{
499+
Lifecycle: wantLifecycle,
500+
})
501+
defer h.mustDeleteBucket(bucket)
498502

499-
attrs := h.mustBucketAttrs(bucket)
500-
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
501-
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
502-
}
503+
attrs := h.mustBucketAttrs(bucket)
504+
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
505+
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
506+
}
503507

504-
// Remove lifecycle rules
505-
ua := BucketAttrsToUpdate{Lifecycle: &Lifecycle{}}
506-
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
507-
if !testutil.Equal(attrs.Lifecycle, Lifecycle{}) {
508-
t.Fatalf("got %v, want %v", attrs.Lifecycle, Lifecycle{})
509-
}
508+
// Remove lifecycle rules
509+
ua := BucketAttrsToUpdate{Lifecycle: &Lifecycle{}}
510+
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
511+
if !testutil.Equal(attrs.Lifecycle, Lifecycle{}) {
512+
t.Fatalf("got %v, want %v", attrs.Lifecycle, Lifecycle{})
513+
}
510514

511-
// Update bucket with a lifecycle rule
512-
ua = BucketAttrsToUpdate{Lifecycle: &wantLifecycle}
513-
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
514-
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
515-
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
516-
}
515+
// Update bucket with a lifecycle rule
516+
ua = BucketAttrsToUpdate{Lifecycle: &wantLifecycle}
517+
attrs = h.mustUpdateBucket(bucket, ua, attrs.MetaGeneration)
518+
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
519+
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
520+
}
521+
})
517522
}
518523

519524
func TestIntegration_BucketUpdate(t *testing.T) {
@@ -1330,64 +1335,54 @@ func TestIntegration_CancelWriteGRPC(t *testing.T) {
13301335
}
13311336

13321337
func TestIntegration_MultiMessageWriteGRPC(t *testing.T) {
1333-
ctx := context.Background()
1334-
1335-
// Create an HTTP client to read test data and a gRPC client to test write
1336-
// with.
1337-
hc := testConfig(ctx, t)
1338-
defer hc.Close()
1339-
gc := testConfigGRPC(ctx, t)
1340-
defer gc.Close()
1338+
multiTransportTest(skipHTTP("gRPC implementation specific test"), t, func(t *testing.T, ctx context.Context, bucket string, _ string, client *Client) {
1339+
h := testHelper{t}
13411340

1342-
name := uidSpace.New()
1343-
gobj := gc.Bucket(grpcBucketName).Object(name).Retryer(WithPolicy(RetryAlways))
1344-
hobj := hc.Bucket(grpcBucketName).Object(name).Retryer(WithPolicy(RetryAlways))
1345-
defer func() {
1346-
if err := hobj.Delete(ctx); err != nil {
1347-
log.Printf("failed to delete test object: %v", err)
1348-
}
1349-
}()
1341+
name := uidSpace.New()
1342+
obj := client.Bucket(bucket).Object(name).Retryer(WithPolicy(RetryAlways))
1343+
defer h.mustDeleteObject(obj)
13501344

1351-
// Use a larger blob to test multi-message logic. This is a little over 5MB.
1352-
content := bytes.Repeat([]byte("a"), 5<<20)
1345+
// Use a larger blob to test multi-message logic. This is a little over 5MB.
1346+
content := bytes.Repeat([]byte("a"), 5<<20)
13531347

1354-
crc32c := crc32.Checksum(content, crc32cTable)
1355-
w := gobj.NewWriter(ctx)
1356-
w.ProgressFunc = func(p int64) {
1357-
t.Logf("%s: committed %d\n", t.Name(), p)
1358-
}
1359-
w.SendCRC32C = true
1360-
w.CRC32C = crc32c
1361-
got, err := w.Write(content)
1362-
if err != nil {
1363-
t.Fatalf("Writer.Write: %v", err)
1364-
}
1365-
// Flush the buffer to finish the upload.
1366-
if err := w.Close(); err != nil {
1367-
t.Fatalf("Writer.Close: %v", err)
1368-
}
1348+
crc32c := crc32.Checksum(content, crc32cTable)
1349+
w := obj.NewWriter(ctx)
1350+
w.ProgressFunc = func(p int64) {
1351+
t.Logf("%s: committed %d\n", t.Name(), p)
1352+
}
1353+
w.SendCRC32C = true
1354+
w.CRC32C = crc32c
1355+
got, err := w.Write(content)
1356+
if err != nil {
1357+
t.Fatalf("Writer.Write: %v", err)
1358+
}
1359+
// Flush the buffer to finish the upload.
1360+
if err := w.Close(); err != nil {
1361+
t.Fatalf("Writer.Close: %v", err)
1362+
}
13691363

1370-
want := len(content)
1371-
if got != want {
1372-
t.Errorf("While writing got: %d want %d", got, want)
1373-
}
1364+
want := len(content)
1365+
if got != want {
1366+
t.Errorf("While writing got: %d want %d", got, want)
1367+
}
13741368

1375-
// Use HTTP client to read back the Object for verification.
1376-
hr, err := hc.Bucket(grpcBucketName).Object(name).NewReader(ctx)
1377-
if err != nil {
1378-
t.Fatal(err)
1379-
}
1380-
defer hr.Close()
1369+
// Read back the Object for verification.
1370+
reader, err := client.Bucket(bucket).Object(name).NewReader(ctx)
1371+
if err != nil {
1372+
t.Fatal(err)
1373+
}
1374+
defer reader.Close()
13811375

1382-
buf := make([]byte, want+4<<10)
1383-
b := bytes.NewBuffer(buf)
1384-
gotr, err := io.Copy(b, hr)
1385-
if err != nil {
1386-
t.Fatal(err)
1387-
}
1388-
if gotr != int64(want) {
1389-
t.Errorf("While reading got: %d want %d", gotr, want)
1390-
}
1376+
buf := make([]byte, want+4<<10)
1377+
b := bytes.NewBuffer(buf)
1378+
gotr, err := io.Copy(b, reader)
1379+
if err != nil {
1380+
t.Fatal(err)
1381+
}
1382+
if gotr != int64(want) {
1383+
t.Errorf("While reading got: %d want %d", gotr, want)
1384+
}
1385+
})
13911386
}
13921387

13931388
func TestIntegration_MultiChunkWriteGRPC(t *testing.T) {
@@ -5048,3 +5043,11 @@ func retry(ctx context.Context, call func() error, check func() error) error {
50485043
time.Sleep(200 * time.Millisecond)
50495044
}
50505045
}
5046+
5047+
func skipGRPC(reason string) context.Context {
5048+
return context.WithValue(context.Background(), skipTransportTestKey("grpc"), reason)
5049+
}
5050+
5051+
func skipHTTP(reason string) context.Context {
5052+
return context.WithValue(context.Background(), skipTransportTestKey("http"), reason)
5053+
}

0 commit comments

Comments
 (0)