diff --git a/cmd/bucket-cors-site-replication_test.go b/cmd/bucket-cors-site-replication_test.go index 275d0fa01..ae23e93c0 100644 --- a/cmd/bucket-cors-site-replication_test.go +++ b/cmd/bucket-cors-site-replication_test.go @@ -511,14 +511,13 @@ func testSiteReplicationStatusDetectsCorsTimestampMismatch(obj ObjectLayer, _ st })) defer remote.Close() - serviceCred, err := auth.CreateCredentials("cors-status-service", "cors-status-service-secret-key") + serviceCred, _, err := globalIAMSys.NewServiceAccount(ctx, credentials.AccessKey, nil, newServiceAccountOpts{ + accessKey: "cors-status-service", + secretKey: "cors-status-service-secret-key", + }) if err != nil { t.Fatal(err) } - serviceCred.ParentUser = credentials.AccessKey - if _, err = globalIAMSys.store.AddServiceAccount(ctx, serviceCred); err != nil { - t.Fatal(err) - } defer globalIAMSys.DeleteServiceAccount(ctx, serviceCred.AccessKey, false) globalSiteReplicationSys.Lock() @@ -585,14 +584,13 @@ func testSiteReplicationStatusCountsCorsPerSite(obj ObjectLayer, _ string, bucke })) defer remote.Close() - serviceCred, err := auth.CreateCredentials("cors-count-service", "cors-count-service-secret-key") + serviceCred, _, err := globalIAMSys.NewServiceAccount(ctx, credentials.AccessKey, nil, newServiceAccountOpts{ + accessKey: "cors-count-service", + secretKey: "cors-count-service-secret-key", + }) if err != nil { t.Fatal(err) } - serviceCred.ParentUser = credentials.AccessKey - if _, err = globalIAMSys.store.AddServiceAccount(ctx, serviceCred); err != nil { - t.Fatal(err) - } defer globalIAMSys.DeleteServiceAccount(ctx, serviceCred.AccessKey, false) globalSiteReplicationSys.Lock() @@ -1190,14 +1188,13 @@ func testCorsReplicationDispatchStatusHealReload(obj ObjectLayer, _ string, buck })) defer remote.Close() - serviceCred, err := auth.CreateCredentials("cors-integration-svc", "cors-integration-service-secret") + serviceCred, _, err := globalIAMSys.NewServiceAccount(ctx, credentials.AccessKey, nil, newServiceAccountOpts{ + accessKey: "cors-integration-svc", + secretKey: "cors-integration-service-secret", + }) if err != nil { t.Fatal(err) } - serviceCred.ParentUser = credentials.AccessKey - if _, err = globalIAMSys.store.AddServiceAccount(ctx, serviceCred); err != nil { - t.Fatal(err) - } defer globalIAMSys.DeleteServiceAccount(ctx, serviceCred.AccessKey, false) globalSiteReplicationSys.Lock() diff --git a/cmd/endpoint-ellipses_test.go b/cmd/endpoint-ellipses_test.go index 58b478c73..b457de76e 100644 --- a/cmd/endpoint-ellipses_test.go +++ b/cmd/endpoint-ellipses_test.go @@ -27,6 +27,7 @@ import ( // Tests create endpoints with ellipses and without. func TestCreateServerEndpoints(t *testing.T) { + useStaticTestEndpoints(t) testCases := []struct { serverAddr string args []string diff --git a/cmd/endpoint_test.go b/cmd/endpoint_test.go index 1eb034ed9..98b610168 100644 --- a/cmd/endpoint_test.go +++ b/cmd/endpoint_test.go @@ -27,6 +27,14 @@ import ( "testing" ) +func useStaticTestEndpoints(t *testing.T) { + t.Helper() + // These fixtures deliberately use localhost, including inside containers. + previous := orchestrated + orchestrated = false + t.Cleanup(func() { orchestrated = previous }) +} + func TestNewEndpoint(t *testing.T) { u2, _ := url.Parse("https://example.org/path") u4, _ := url.Parse("http://192.168.253.200/path") @@ -130,6 +138,7 @@ func TestNewEndpoints(t *testing.T) { } func TestCreateEndpoints(t *testing.T) { + useStaticTestEndpoints(t) tempGlobalMinioPort := globalMinioPort defer func() { globalMinioPort = tempGlobalMinioPort @@ -353,6 +362,7 @@ func TestCreateEndpoints(t *testing.T) { // So it means that if you have say localhost:9000 and localhost:9001 as endpointArgs then localhost:9001 // is considered a remote service from localhost:9000 perspective. func TestGetLocalPeer(t *testing.T) { + useStaticTestEndpoints(t) tempGlobalMinioPort := globalMinioPort defer func() { globalMinioPort = tempGlobalMinioPort @@ -393,6 +403,7 @@ func TestGetLocalPeer(t *testing.T) { } func TestGetRemotePeers(t *testing.T) { + useStaticTestEndpoints(t) tempGlobalMinioPort := globalMinioPort defer func() { globalMinioPort = tempGlobalMinioPort diff --git a/cmd/metacache-null-quorum_test.go b/cmd/metacache-null-quorum_test.go index d4cf74351..ee88f0cfa 100644 --- a/cmd/metacache-null-quorum_test.go +++ b/cmd/metacache-null-quorum_test.go @@ -815,11 +815,22 @@ func scanNullQuorumAbandoned(t *testing.T, z *erasureServerPools, bucket, object disks := z.serverPools[0].sets[0].getDisks() seq := newBgHealSequence() defer seq.cancelCtx() - previousState, previousRoutine := globalBackgroundHealState, globalBackgroundHealRoutine - globalBackgroundHealState = &allHealState{healSeqMap: map[string]*healSequence{"test": seq}} + // Disk monitors may still read the shared state between object-layer tests. + // Install the test sequence under its lock without replacing the state. + state := globalBackgroundHealState + state.Lock() + previousSequences := state.healSeqMap + state.healSeqMap = map[string]*healSequence{"test": seq} + state.Unlock() + previousRoutine := globalBackgroundHealRoutine routine := &healRoutine{tasks: make(chan healTask)} globalBackgroundHealRoutine = routine - defer func() { globalBackgroundHealState, globalBackgroundHealRoutine = previousState, previousRoutine }() + defer func() { + globalBackgroundHealRoutine = previousRoutine + state.Lock() + state.healSeqMap = previousSequences + state.Unlock() + }() workerDone := make(chan struct{}) var healed []string go func() { diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 6bd362ffd..54701298a 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -503,6 +503,8 @@ func resetTestGlobals() { resetGlobalHealState() // Reset globalIAMSys to `nil` resetGlobalIAMSys() + // Object-layer fixtures must not reuse the preceding IAM suite's etcd store. + globalEtcdClient = nil } // Configure the server for the test run.