diff --git a/cmd/lockinfo-handlers_test.go b/cmd/lockinfo-handlers_test.go index d71108f84..36d641c8a 100644 --- a/cmd/lockinfo-handlers_test.go +++ b/cmd/lockinfo-handlers_test.go @@ -18,27 +18,38 @@ package cmd import ( "fmt" + "os" "testing" "time" ) // TestListLocksInfo - Test for listLocksInfo. func TestListLocksInfo(t *testing.T) { - // Initialize globalNSMutex to validate listing of lock - // instrumentation information. + // reset global variables to start afresh. + resetTestGlobals() + // Initialize minio server config. + rootPath, err := newTestConfig(globalMinioDefaultRegion) + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(rootPath) + // Initializing new XL objectLayer. + objAPI, _, xlErr := initTestXLObjLayer() + if xlErr != nil { + t.Fatalf("failed to init object layer") + } + // Make objLayer available to all internal services via globalObjectAPI. + globalObjLayerMutex.Lock() + globalObjectAPI = objAPI + globalObjLayerMutex.Unlock() + // Set globalIsXL to indicate that the setup uses an erasure code backend. + // initialize NSLock. isDistXL := false initNSLock(isDistXL) - objAPI := newObjectLayerFn() - if objAPI == nil { - t.Errorf("Failed to initialize object layer") - } + var nsMutex *nsLockMap - switch objAPI.(type) { - case *fsObjects: - nsMutex = objAPI.(*fsObjects).nsMutex - case *xlObjects: - nsMutex = objAPI.(*xlObjects).nsMutex - } + + nsMutex = objAPI.(*xlObjects).nsMutex // Acquire a few locks to populate lock instrumentation. // Take 10 read locks on bucket1/prefix1/obj1 diff --git a/cmd/namespace-lock_test.go b/cmd/namespace-lock_test.go index 2e9a95865..1e868370d 100644 --- a/cmd/namespace-lock_test.go +++ b/cmd/namespace-lock_test.go @@ -39,6 +39,8 @@ func TestGetSource(t *testing.T) { // Tests functionality provided by namespace lock. func TestNamespaceLockTest(t *testing.T) { + isDistXL := false + initNSLock(isDistXL) // List of test cases. testCases := []struct { lk func(s1, s2, s3 string, t time.Duration) bool @@ -155,7 +157,8 @@ func TestNamespaceLockTest(t *testing.T) { } func TestNamespaceLockTimedOut(t *testing.T) { - + isDistXL := false + initNSLock(isDistXL) // Get write lock if !globalNSMutex.Lock("my-bucket", "my-object", "abc", 60*time.Second) { t.Fatalf("Failed to acquire lock") @@ -199,7 +202,8 @@ func TestNamespaceLockTimedOut(t *testing.T) { // Tests functionality to forcefully unlock locks. func TestNamespaceForceUnlockTest(t *testing.T) { - + isDistXL := false + initNSLock(isDistXL) // Create lock. lock := globalNSMutex.NewNSLock("bucket", "object") if lock.GetLock(newDynamicTimeout(60*time.Second, time.Second)) != nil {