fix: use per test context (#9343)

Instead of GlobalContext use a local context for tests.
Most notably this allows stuff created to be shut down 
when tests using it is done. After PR #9345 9331 CI is 
often running out of memory/time.
This commit is contained in:
Klaus Post
2020-04-15 02:52:38 +02:00
committed by GitHub
parent 78f2183e70
commit f19cbfad5c
15 changed files with 227 additions and 132 deletions
+6 -6
View File
@@ -25,8 +25,11 @@ import (
// Tests cleanup multipart uploads for erasure coded backend.
func TestXLCleanupStaleMultipartUploads(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Create an instance of xl backend
obj, fsDirs, err := prepareXL16()
obj, fsDirs, err := prepareXL16(ctx)
if err != nil {
t.Fatal(err)
}
@@ -40,15 +43,12 @@ func TestXLCleanupStaleMultipartUploads(t *testing.T) {
objectName := "object"
var opts ObjectOptions
obj.MakeBucketWithLocation(GlobalContext, bucketName, "")
obj.MakeBucketWithLocation(ctx, bucketName, "")
uploadID, err := obj.NewMultipartUpload(GlobalContext, bucketName, objectName, opts)
if err != nil {
t.Fatal("Unexpected err: ", err)
}
// Create a context we can cancel.
ctx, cancel := context.WithCancel(GlobalContext)
var cleanupWg sync.WaitGroup
cleanupWg.Add(1)
go func() {
@@ -65,7 +65,7 @@ func TestXLCleanupStaleMultipartUploads(t *testing.T) {
cleanupWg.Wait()
// Check if upload id was already purged.
if err = obj.AbortMultipartUpload(GlobalContext, bucketName, objectName, uploadID); err != nil {
if err = obj.AbortMultipartUpload(context.Background(), bucketName, objectName, uploadID); err != nil {
if _, ok := err.(InvalidUploadID); !ok {
t.Fatal("Unexpected err: ", err)
}