From a85b1f6878f6e472b29ca5f29e65ad399b76734f Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Mon, 27 Mar 2023 23:30:25 +0400 Subject: [PATCH] Always call unlock after successful lock --- keylock/keylock_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/keylock/keylock_test.go b/keylock/keylock_test.go index 4888ac8..171d0e0 100644 --- a/keylock/keylock_test.go +++ b/keylock/keylock_test.go @@ -25,33 +25,36 @@ func TestKeyLock_Simple(t *testing.T) { l := keylock.New() - canceled, unlock := l.LockKeys([]string{"a", "b"}, nil) + canceled, unlock0 := l.LockKeys([]string{"a", "b"}, nil) require.False(t, canceled) canceled, _ = l.LockKeys([]string{"", "b", "c"}, timeout(time.Millisecond*10)) require.True(t, canceled) - unlock() + unlock0() - canceled, _ = l.LockKeys([]string{"", "b", "c"}, nil) + canceled, unlock1 := l.LockKeys([]string{"", "b", "c"}, nil) require.False(t, canceled) + unlock1() } func TestKeyLock_Progress(t *testing.T) { defer goleak.VerifyNone(t) l := keylock.New() - canceled, unlock := l.LockKeys([]string{"a", "b"}, nil) + canceled, unlock0 := l.LockKeys([]string{"a", "b"}, nil) require.False(t, canceled) - defer unlock() + defer unlock0() go func() { - _, _ = l.LockKeys([]string{"b", "c"}, nil) + _, unlock := l.LockKeys([]string{"b", "c"}, nil) + unlock() }() time.Sleep(time.Millisecond * 10) - canceled, _ = l.LockKeys([]string{"d"}, nil) + canceled, unlock1 := l.LockKeys([]string{"d"}, nil) require.False(t, canceled) + unlock1() } func TestKeyLock_DeadlockFree(t *testing.T) {