mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
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:
@@ -187,7 +187,7 @@ func calculateStreamContentLength(dataLen, chunkSize int64) int64 {
|
||||
return streamLen
|
||||
}
|
||||
|
||||
func prepareFS() (ObjectLayer, string, error) {
|
||||
func prepareFS(ctx context.Context) (ObjectLayer, string, error) {
|
||||
nDisks := 1
|
||||
fsDirs, err := getRandomDisks(nDisks)
|
||||
if err != nil {
|
||||
@@ -198,9 +198,9 @@ func prepareFS() (ObjectLayer, string, error) {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
|
||||
globalIAMSys.Init(context.Background(), obj, globalEtcdClient, 2*time.Second)
|
||||
globalIAMSys.Init(ctx, obj, globalEtcdClient, 2*time.Second)
|
||||
return obj, fsDirs[0], nil
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ func initFSObjects(disk string, t *testing.T) (obj ObjectLayer) {
|
||||
|
||||
newTestConfig(globalMinioDefaultRegion, obj)
|
||||
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(GlobalContext)
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ func initTestServerWithBackend(ctx context.Context, t TestErrHandler, testServer
|
||||
globalMinioPort = port
|
||||
globalMinioAddr = getEndpointsLocalAddr(testServer.Disks)
|
||||
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
|
||||
globalEtcdClient = nil
|
||||
|
||||
@@ -445,7 +445,7 @@ func resetGlobalIsErasure() {
|
||||
func resetGlobalHealState() {
|
||||
// Init global heal state
|
||||
if globalAllHealState == nil {
|
||||
globalAllHealState = newHealState(false)
|
||||
globalAllHealState = newHealState(GlobalContext, false)
|
||||
} else {
|
||||
globalAllHealState.Lock()
|
||||
for _, v := range globalAllHealState.healSeqMap {
|
||||
@@ -458,7 +458,7 @@ func resetGlobalHealState() {
|
||||
|
||||
// Init background heal state
|
||||
if globalBackgroundHealState == nil {
|
||||
globalBackgroundHealState = newHealState(false)
|
||||
globalBackgroundHealState = newHealState(GlobalContext, false)
|
||||
} else {
|
||||
globalBackgroundHealState.Lock()
|
||||
for _, v := range globalBackgroundHealState.healSeqMap {
|
||||
@@ -1474,7 +1474,7 @@ func getRandomDisks(N int) ([]string, error) {
|
||||
|
||||
// Initialize object layer with the supplied disks, objectLayer is nil upon any error.
|
||||
func newTestObjectLayer(ctx context.Context, endpointServerPools EndpointServerPools) (newObject ObjectLayer, err error) {
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
|
||||
return newErasureServerPools(ctx, endpointServerPools)
|
||||
}
|
||||
@@ -1518,7 +1518,7 @@ func removeDiskN(disks []string, n int) {
|
||||
// initialies the root and returns its path.
|
||||
// return credentials.
|
||||
func initAPIHandlerTest(ctx context.Context, obj ObjectLayer, endpoints []string) (string, http.Handler, error) {
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
|
||||
initConfigSubsystem(ctx, obj)
|
||||
|
||||
@@ -1556,7 +1556,7 @@ func prepareTestBackend(ctx context.Context, instanceType string) (ObjectLayer,
|
||||
return prepareErasure16(ctx)
|
||||
default:
|
||||
// return FS backend by default.
|
||||
obj, disk, err := prepareFS()
|
||||
obj, disk, err := prepareFS(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -1725,7 +1725,7 @@ func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints [
|
||||
// this is to make sure that the tests are not affected by modified value.
|
||||
resetTestGlobals()
|
||||
|
||||
objLayer, fsDir, err := prepareFS()
|
||||
objLayer, fsDir, err := prepareFS(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Initialization of object layer failed for single node setup: %s", err)
|
||||
}
|
||||
@@ -1793,13 +1793,12 @@ func ExecObjectLayerTest(t TestErrHandler, objTest objTestType) {
|
||||
localMetacacheMgr.deleteAll()
|
||||
}
|
||||
|
||||
objLayer, fsDir, err := prepareFS()
|
||||
objLayer, fsDir, err := prepareFS(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Initialization of object layer failed for single node setup: %s", err)
|
||||
}
|
||||
setObjectLayer(objLayer)
|
||||
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
|
||||
// initialize the server and obtain the credentials and root.
|
||||
// credentials are necessary to sign the HTTP request.
|
||||
@@ -1825,7 +1824,7 @@ func ExecObjectLayerTest(t TestErrHandler, objTest objTestType) {
|
||||
localMetacacheMgr.deleteAll()
|
||||
}
|
||||
|
||||
initAllSubsystems()
|
||||
initAllSubsystems(ctx)
|
||||
objLayer, fsDirs, err := prepareErasureSets32(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Initialization of object layer failed for Erasure setup: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user