github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/hyperloglog/hyperloglog_test.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package hyperloglog_test 5 6 import ( 7 "sync" 8 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 wrapper "github.com/pyroscope-io/pyroscope/pkg/util/hyperloglog" 12 "github.com/twmb/murmur3" 13 ) 14 15 type hashString string 16 17 func (hs hashString) Sum64() uint64 { 18 return murmur3.SeedSum64(123, []byte(hs)) 19 } 20 21 var _ = Describe("Hyperloglog", func() { 22 Context("wrapper implementation", func() { 23 // original implementation panics with "concurrent map writes" 24 It("doesn't panic", func() { 25 done := make(chan interface{}) 26 go func() { 27 Expect(func() { 28 h, _ := wrapper.NewPlus(18) 29 count := 10000 30 wg := sync.WaitGroup{} 31 wg.Add(count) 32 for i := 0; i < count; i++ { 33 go func() { 34 h.Add(hashString("test")) 35 wg.Done() 36 }() 37 } 38 wg.Wait() 39 }).ToNot(Panic()) 40 close(done) 41 }() 42 Eventually(done).Should(BeClosed()) 43 }) 44 }) 45 })