diff --git a/pkg/objstore/objtesting/foreach.go b/pkg/objstore/objtesting/foreach.go index 0b5dffcb032..a2759554a0e 100644 --- a/pkg/objstore/objtesting/foreach.go +++ b/pkg/objstore/objtesting/foreach.go @@ -3,9 +3,7 @@ package objtesting import ( "os" "testing" - "time" - "github.com/fortytw2/leaktest" "github.com/thanos-io/thanos/pkg/objstore" "github.com/thanos-io/thanos/pkg/objstore/azure" "github.com/thanos-io/thanos/pkg/objstore/cos" @@ -21,98 +19,98 @@ import ( // that deletes it after test was run. // Use THANOS_SKIP__TESTS to skip explicitly certain tests. func ForeachStore(t *testing.T, testFn func(t testing.TB, bkt objstore.Bucket)) { + t.Parallel() + // Mandatory Inmem. if ok := t.Run("inmem", func(t *testing.T) { - defer leaktest.CheckTimeout(t, 10*time.Second)() - + t.Parallel() testFn(t, inmem.NewBucket()) - }); !ok { return } // Optional GCS. if _, ok := os.LookupEnv("THANOS_SKIP_GCS_TESTS"); !ok { - bkt, closeFn, err := gcs.NewTestBucket(t, os.Getenv("GCP_PROJECT")) - testutil.Ok(t, err) + t.Run("gcs", func(t *testing.T) { + bkt, closeFn, err := gcs.NewTestBucket(t, os.Getenv("GCP_PROJECT")) + testutil.Ok(t, err) + + t.Parallel() + defer closeFn() - ok := t.Run("gcs", func(t *testing.T) { // TODO(bwplotka): Add leaktest when https://github.com/GoogleCloudPlatform/google-cloud-go/issues/1025 is resolved. testFn(t, bkt) }) - closeFn() - if !ok { - return - } + } else { t.Log("THANOS_SKIP_GCS_TESTS envvar present. Skipping test against GCS.") } // Optional S3. if _, ok := os.LookupEnv("THANOS_SKIP_S3_AWS_TESTS"); !ok { - // TODO(bwplotka): Allow taking location from envvar. - bkt, closeFn, err := s3.NewTestBucket(t, "us-west-2") - testutil.Ok(t, err) + t.Run("aws s3", func(t *testing.T) { + // TODO(bwplotka): Allow taking location from envvar. + bkt, closeFn, err := s3.NewTestBucket(t, "us-west-2") + testutil.Ok(t, err) + + t.Parallel() + defer closeFn() - ok := t.Run("aws s3", func(t *testing.T) { // TODO(bwplotka): Add leaktest when we fix potential leak in minio library. // We cannot use leaktest for detecting our own potential leaks, when leaktest detects leaks in minio itself. // This needs to be investigated more. testFn(t, bkt) }) - closeFn() - if !ok { - return - } + } else { t.Log("THANOS_SKIP_S3_AWS_TESTS envvar present. Skipping test against S3 AWS.") } // Optional Azure. if _, ok := os.LookupEnv("THANOS_SKIP_AZURE_TESTS"); !ok { - bkt, closeFn, err := azure.NewTestBucket(t, "e2e-tests") - testutil.Ok(t, err) + t.Run("azure", func(t *testing.T) { + bkt, closeFn, err := azure.NewTestBucket(t, "e2e-tests") + testutil.Ok(t, err) + + t.Parallel() + defer closeFn() - ok := t.Run("azure", func(t *testing.T) { testFn(t, bkt) }) - closeFn() - if !ok { - return - } + } else { t.Log("THANOS_SKIP_AZURE_TESTS envvar present. Skipping test against Azure.") } // Optional SWIFT. if _, ok := os.LookupEnv("THANOS_SKIP_SWIFT_TESTS"); !ok { - container, closeFn, err := swift.NewTestContainer(t) - testutil.Ok(t, err) + t.Run("swift", func(t *testing.T) { + container, closeFn, err := swift.NewTestContainer(t) + testutil.Ok(t, err) + + t.Parallel() + defer closeFn() - ok := t.Run("swift", func(t *testing.T) { testFn(t, container) }) - closeFn() - if !ok { - return - } + } else { t.Log("THANOS_SKIP_SWIFT_TESTS envvar present. Skipping test against swift.") } // Optional COS. if _, ok := os.LookupEnv("THANOS_SKIP_TENCENT_COS_TESTS"); !ok { - bkt, closeFn, err := cos.NewTestBucket(t) - testutil.Ok(t, err) + t.Run("Tencent cos", func(t *testing.T) { + bkt, closeFn, err := cos.NewTestBucket(t) + testutil.Ok(t, err) + + t.Parallel() + defer closeFn() - ok := t.Run("Tencent cos", func(t *testing.T) { testFn(t, bkt) }) - closeFn() - if !ok { - return - } + } else { t.Log("THANOS_SKIP_TENCENT_COS_TESTS envvar present. Skipping test against Tencent COS.") } diff --git a/pkg/objstore/s3/s3.go b/pkg/objstore/s3/s3.go index bf33400a20e..1e84f1561f7 100644 --- a/pkg/objstore/s3/s3.go +++ b/pkg/objstore/s3/s3.go @@ -406,7 +406,7 @@ func NewTestBucketFromConfig(t testing.TB, location string, c Config, reuseBucke src := rand.NewSource(time.Now().UnixNano()) // Bucket name need to conform: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html. - bktToCreate = strings.Replace(fmt.Sprintf("test_%s_%x", strings.ToLower(t.Name()), src.Int63()), "_", "-", -1) + bktToCreate = strings.Replace(strings.Replace(fmt.Sprintf("test_%x_%s", src.Int63(), strings.ToLower(t.Name())), "_", "-", -1), "/", "-", -1) if len(bktToCreate) >= 63 { bktToCreate = bktToCreate[:63] }