tests: Add context cancelation (#15374)

A huge number of goroutines would build up from various monitors

When creating test filesystems provide a context so they can shut down when no longer needed.
This commit is contained in:
Klaus Post
2022-07-21 11:52:18 -07:00
committed by GitHub
parent cab8d3d568
commit 1e332f0eb1
22 changed files with 136 additions and 69 deletions
+5 -2
View File
@@ -19,6 +19,7 @@ package cmd
import (
"bytes"
"context"
"os"
"path/filepath"
"testing"
@@ -29,17 +30,19 @@ import (
// TestNewFS - tests initialization of all input disks
// and constructs a valid `FS` object layer.
func TestNewFS(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Do not attempt to create this path, the test validates
// so that NewFSObjectLayer initializes non existing paths
// and successfully returns initialized object layer.
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
defer os.RemoveAll(disk)
_, err := NewFSObjectLayer("")
_, err := NewFSObjectLayer(ctx, "")
if err != errInvalidArgument {
t.Errorf("Expecting error invalid argument, got %s", err)
}
_, err = NewFSObjectLayer(disk)
_, err = NewFSObjectLayer(ctx, disk)
if err != nil {
errMsg := "Unable to recognize backend format, Disk is not in FS format."
if err.Error() == errMsg {