Skip to content

Commit

Permalink
Trying to speed up tests a bit.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartek Plotka <[email protected]>
  • Loading branch information
bwplotka committed Oct 21, 2019
1 parent f4ec30e commit 3b6ac56
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
80 changes: 39 additions & 41 deletions pkg/objstore/objtesting/foreach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,98 +19,98 @@ import (
// that deletes it after test was run.
// Use THANOS_SKIP_<objstorename>_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.")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down

0 comments on commit 3b6ac56

Please sign in to comment.