Open ceeji opened 3 months ago
@ceeji I have not yet had time to spend time looking into this.
-race
haven't detected any data race.
package main
import (
"sync"
"testing"
"github.com/sqids/sqids-go"
)
func TestRace(t *testing.T) {
s, _ := sqids.New()
const n = 1_000_000
var wg sync.WaitGroup
wg.Add(n)
for _ = range n {
go func() {
defer wg.Done()
id, err := s.Encode([]uint64{42})
if err != nil {
t.Error(err)
panic(err)
}
if id != "Jg" {
t.Error("unexpected id:", id)
panic(err)
}
nums := s.Decode(id)
if len(nums) != 1 && nums[0] != 42 {
t.Error("unexpected nums:", nums)
panic(err)
}
}()
}
wg.Wait()
}
$ go test -test.run ^\QTestRace\E$ -race ./...
Is this package safe for running in multiple goroutine?