Files
zeekayandHanzo Dev cbf668a980 Build on Go 1.27
go fix applied the modernizers: promoted-field keys in struct literals,
strings.Cut, SplitSeq, new(expr), slices and maps helpers, wg.Go, reflect.TypeFor
and errors.AsType. omitzero is left out, since omitting a zero struct such as
time.Time{} is a per-field wire decision and not a mechanical one.

Two changes the modernizers could not make for themselves. AsType needs its type
argument to be an error, so the git exit-status reader embeds error in the
interface it asks for. And an error built by concatenating a tag list into its
own format string now says so with a verb, which is what vet was pointing at.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:47:46 -07:00

102 lines
1.2 KiB
Go

package sync
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLockLock(t *testing.T) {
l := NewKeyLock()
l.Lock("my-key")
unlocked := false
wg := sync.WaitGroup{}
wg.Go(func() {
l.Lock("my-key")
unlocked = true
})
assert.False(t, unlocked)
l.Unlock("my-key")
wg.Wait()
assert.True(t, unlocked)
l.Unlock("my-key")
}
func TestLockRLock(t *testing.T) {
l := NewKeyLock()
l.Lock("my-key")
unlocked := false
wg := sync.WaitGroup{}
wg.Go(func() {
l.RLock("my-key")
unlocked = true
})
assert.False(t, unlocked)
l.Unlock("my-key")
wg.Wait()
assert.True(t, unlocked)
l.RUnlock("my-key")
}
func TestRLockLock(t *testing.T) {
l := NewKeyLock()
l.RLock("my-key")
unlocked := false
wg := sync.WaitGroup{}
wg.Go(func() {
l.Lock("my-key")
unlocked = true
})
assert.False(t, unlocked)
l.RUnlock("my-key")
wg.Wait()
assert.True(t, unlocked)
l.Unlock("my-key")
}
func TestRLockRLock(t *testing.T) {
l := NewKeyLock()
l.RLock("my-key")
unlocked := false
wg := sync.WaitGroup{}
wg.Go(func() {
l.RLock("my-key")
unlocked = true
})
wg.Wait()
assert.True(t, unlocked)
l.RUnlock("my-key")
l.RUnlock("my-key")
}