// set debug lock info to `nil` so that the next tests have to initialize them again.
deferfunc(){
globalDebugLock=false
nsMutex.debugLockMap=nil
}()
expectedResult:=[]lockStateCase{
// Test case - 1.
// Case where 10 read locks are held.
// Entry for any of the 10 reads locks has to be found.
// Since they held in a loop, Lock origin for first 10 read locks (opsID 0-9) should be the same.
{
volume:"my-bucket",
path:"my-object",
opsID:"0",
readLock:true,
lockOrigin:"[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
lockOrigin:"[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics.
expectedErr:nil,
expectedLockStatus:"Running",
expectedGlobalLockCount:10,
expectedRunningLockCount:10,
expectedBlockedLockCount:0,
expectedVolPathLockCount:10,
expectedVolPathRunningCount:10,
expectedVolPathBlockCount:0,
},
// Test case 3.
// Hold a write lock, and it should block since 10 read locks
// on <"my-bucket", "my-object"> are still held.
{
volume:"my-bucket",
path:"my-object",
opsID:"10",
readLock:false,
lockOrigin:"[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics.
expectedErr:nil,
expectedLockStatus:"Blocked",
expectedGlobalLockCount:11,
expectedRunningLockCount:10,
expectedBlockedLockCount:1,
expectedVolPathLockCount:11,
expectedVolPathRunningCount:10,
expectedVolPathBlockCount:1,
},
// Test case 4.
// Expected result when all the read locks are released and the blocked write lock acquires the lock.
{
volume:"my-bucket",
path:"my-object",
opsID:"10",
readLock:false,
lockOrigin:"[lock held] in github.com/minio/minio/cmd.TestLockStats[/Users/hackintoshrao/mycode/go/src/github.com/minio/minio/cmd/namespace-lock_test.go:298]",
// expected metrics.
expectedErr:nil,
expectedLockStatus:"Running",
expectedGlobalLockCount:1,
expectedRunningLockCount:1,
expectedBlockedLockCount:0,
expectedVolPathLockCount:1,
expectedVolPathRunningCount:1,
expectedVolPathBlockCount:0,
},
// Test case - 5.
// At the end after locks are released, its verified whether the counters are set to 0.
{
volume:"my-bucket",
path:"my-object",
// expected metrics.
expectedErr:nil,
expectedLockStatus:"Blocked",
expectedGlobalLockCount:0,
expectedRunningLockCount:0,
expectedBlockedLockCount:0,
},
}
// used to make sure that the tests don't end till locks held in other go routines are released.
varwgsync.WaitGroup
// Hold 5 read locks. We should find the info about these in the RPC response.
// hold 10 read locks.
// Then call the RPC control end point for obtaining lock instrumentation info.