fix testcases to init nslock properly (#5429)

master
poornas 7 years ago committed by Nitish Tiwari
parent 2d19663fef
commit 2dd117f647
  1. 33
      cmd/lockinfo-handlers_test.go
  2. 8
      cmd/namespace-lock_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
}
// Acquire a few locks to populate lock instrumentation.
// Take 10 read locks on bucket1/prefix1/obj1

@ -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 {

Loading…
Cancel
Save