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)
}
