Files
xgcl/internal/spinlock_test.go
2026-05-27 23:03:00 +08:00

28 lines
380 B
Go

package internal
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSpinlock(t *testing.T) {
var l SpinLock
var n uint64
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
for i := 0; i < 10000; i++ {
l.Lock()
n++
l.Unlock()
}
wg.Done()
}()
}
wg.Wait()
assert.Equal(t, n, uint64(10000)*10000)
}