MCPcopy
hub / github.com/kopia/kopia / TestMutexMap_SharedLock

Function TestMutexMap_SharedLock

internal/cache/mutex_map_test.go:29–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestMutexMap_SharedLock(t *testing.T) {
30 var m mutexMap
31
32 require.Empty(t, m.entries)
33 m.sharedLock("foo")
34 require.Len(t, m.entries, 1)
35 m.sharedLock("foo")
36 require.Len(t, m.entries, 1)
37 require.True(t, m.trySharedLock("foo"))
38 require.Len(t, m.entries, 1)
39
40 // exclusive lock can't be acquired while shared lock is held
41 require.False(t, m.tryExclusiveLock("foo"))
42 m.sharedUnlock("foo")
43 require.False(t, m.tryExclusiveLock("foo"))
44 m.sharedUnlock("foo")
45 require.False(t, m.tryExclusiveLock("foo"))
46 m.sharedUnlock("foo")
47
48 // now exclusive lock can be acquired
49 require.True(t, m.tryExclusiveLock("foo"))
50}

Callers

nothing calls this directly

Calls 5

sharedLockMethod · 0.95
trySharedLockMethod · 0.95
tryExclusiveLockMethod · 0.95
sharedUnlockMethod · 0.95
LenMethod · 0.45

Tested by

no test coverage detected