mirror of
https://github.com/talent-plan/tinykv.git
synced 2025-02-07 18:20:19 +08:00
5e089a2cd1
Signed-off-by: Connor <zbk602423539@gmail.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: linning <linningde25@gmail.com> Co-authored-by: YangKeao <keao.yang@yahoo.com> Co-authored-by: andylokandy <andylokandy@hotmail.com> Co-authored-by: Iosmanthus Teng <myosmanthustree@gmail.com>
31 lines
656 B
Go
31 lines
656 B
Go
package latches
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestAcquireLatches(t *testing.T) {
|
|
l := Latches{
|
|
latchMap: make(map[string]*sync.WaitGroup),
|
|
}
|
|
|
|
// Acquiring a new latch is ok.
|
|
wg := l.AcquireLatches([][]byte{{}, {3}, {3, 0, 42}})
|
|
assert.Nil(t, wg)
|
|
|
|
// Can only acquire once.
|
|
wg = l.AcquireLatches([][]byte{{}})
|
|
assert.NotNil(t, wg)
|
|
wg = l.AcquireLatches([][]byte{{3, 0, 42}})
|
|
assert.NotNil(t, wg)
|
|
|
|
// Release then acquire is ok.
|
|
l.ReleaseLatches([][]byte{{3}, {3, 0, 43}})
|
|
wg = l.AcquireLatches([][]byte{{3}})
|
|
assert.Nil(t, wg)
|
|
wg = l.AcquireLatches([][]byte{{3, 0, 42}})
|
|
assert.NotNil(t, wg)
|
|
}
|