summaryrefslogtreecommitdiffhomepage
path: root/pkg/sync/downgradable_rwmutex_test.go
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2020-01-21 18:34:24 -0800
committergVisor bot <gvisor-bot@google.com>2020-01-21 19:11:18 -0800
commitd0e75f2bef4e16356693987db6ae6bbdce749618 (patch)
tree519ba9b2251b143b0115b2ae31d5c904e11b23f8 /pkg/sync/downgradable_rwmutex_test.go
parent1effdc091b441c4b1ada4327c1422cd360f80f98 (diff)
Add trylock support to DowngradableRWMutex.
Updates #231 PiperOrigin-RevId: 290868875
Diffstat (limited to 'pkg/sync/downgradable_rwmutex_test.go')
-rw-r--r--pkg/sync/downgradable_rwmutex_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/pkg/sync/downgradable_rwmutex_test.go b/pkg/sync/downgradable_rwmutex_test.go
index f04496bc5..b5cb28ec0 100644
--- a/pkg/sync/downgradable_rwmutex_test.go
+++ b/pkg/sync/downgradable_rwmutex_test.go
@@ -148,3 +148,58 @@ func TestDowngradableRWMutex(t *testing.T) {
HammerDowngradableRWMutex(10, 10, n)
HammerDowngradableRWMutex(10, 5, n)
}
+
+func TestRWDoubleTryLock(t *testing.T) {
+ var m DowngradableRWMutex
+ if !m.TryLock() {
+ t.Fatal("failed to aquire lock")
+ }
+ if m.TryLock() {
+ t.Fatal("unexpectedly succeeded in aquiring locked mutex")
+ }
+}
+
+func TestRWTryLockAfterLock(t *testing.T) {
+ var m DowngradableRWMutex
+ m.Lock()
+ if m.TryLock() {
+ t.Fatal("unexpectedly succeeded in aquiring locked mutex")
+ }
+}
+
+func TestRWTryLockUnlock(t *testing.T) {
+ var m DowngradableRWMutex
+ if !m.TryLock() {
+ t.Fatal("failed to aquire lock")
+ }
+ m.Unlock()
+ if !m.TryLock() {
+ t.Fatal("failed to aquire lock after unlock")
+ }
+}
+
+func TestTryRLockAfterLock(t *testing.T) {
+ var m DowngradableRWMutex
+ m.Lock()
+ if m.TryRLock() {
+ t.Fatal("unexpectedly succeeded in aquiring locked mutex")
+ }
+}
+
+func TestTryLockAfterRLock(t *testing.T) {
+ var m DowngradableRWMutex
+ m.RLock()
+ if m.TryLock() {
+ t.Fatal("unexpectedly succeeded in aquiring locked mutex")
+ }
+}
+
+func TestDoubleTryRLock(t *testing.T) {
+ var m DowngradableRWMutex
+ if !m.TryRLock() {
+ t.Fatal("failed to aquire lock")
+ }
+ if !m.TryRLock() {
+ t.Fatal("failed to read aquire read locked lock")
+ }
+}