mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 07:26:47 +00:00
* golangci-lint/CI: Bump versions
Fix remaining linter issues
* Specifically set AppVeyor version
* Fix the infamous typos 👀
* Add go env cmd to AppVeyor
* Add go version cmd to AppVeyor
* Specify AppVeyor image, adjust linters
* Update go get to go install due to deprecation
* Bump golangci-lint timeout time for AppVeyor
* Change NW contract to NQ
* Address nitters
* GetRandomPair -> Pair{}
* Address nits
* Address time nitterinos plus additional tweaks
* More time inception upgrades!
* Bending time and space
93 lines
1.7 KiB
Go
93 lines
1.7 KiB
Go
package alert
|
|
|
|
import (
|
|
"log"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWait(t *testing.T) {
|
|
wait := Notice{}
|
|
var wg sync.WaitGroup
|
|
|
|
// standard alert
|
|
wg.Add(100)
|
|
for x := 0; x < 100; x++ {
|
|
go func() {
|
|
w := wait.Wait(nil)
|
|
wg.Done()
|
|
if <-w {
|
|
log.Fatal("incorrect routine wait response for alert expecting false")
|
|
}
|
|
wg.Done()
|
|
}()
|
|
}
|
|
|
|
wg.Wait()
|
|
wg.Add(100)
|
|
isLeaky(t, &wait, nil)
|
|
wait.Alert()
|
|
wg.Wait()
|
|
isLeaky(t, &wait, nil)
|
|
|
|
// use kick
|
|
ch := make(chan struct{})
|
|
wg.Add(100)
|
|
for x := 0; x < 100; x++ {
|
|
go func() {
|
|
w := wait.Wait(ch)
|
|
wg.Done()
|
|
if !<-w {
|
|
log.Fatal("incorrect routine wait response for kick expecting true")
|
|
}
|
|
wg.Done()
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
wg.Add(100)
|
|
isLeaky(t, &wait, ch)
|
|
close(ch)
|
|
wg.Wait()
|
|
ch = make(chan struct{})
|
|
isLeaky(t, &wait, ch)
|
|
|
|
// late receivers
|
|
wg.Add(100)
|
|
for x := 0; x < 100; x++ {
|
|
go func(x int) {
|
|
bb := wait.Wait(ch)
|
|
wg.Done()
|
|
if x%2 == 0 {
|
|
time.Sleep(time.Millisecond * 5)
|
|
}
|
|
b := <-bb
|
|
if b {
|
|
log.Fatal("incorrect routine wait response since we call alert below; expecting false")
|
|
}
|
|
wg.Done()
|
|
}(x)
|
|
}
|
|
wg.Wait()
|
|
wg.Add(100)
|
|
isLeaky(t, &wait, ch)
|
|
wait.Alert()
|
|
wg.Wait()
|
|
isLeaky(t, &wait, ch)
|
|
}
|
|
|
|
// isLeaky tests to see if the wait functionality is returning an abnormal
|
|
// channel that is operational when it shouldn't be.
|
|
func isLeaky(t *testing.T, a *Notice, ch chan struct{}) {
|
|
t.Helper()
|
|
check := a.Wait(ch)
|
|
time.Sleep(time.Millisecond * 5) // When we call wait a routine for hold is
|
|
// spawned, so for a test we need to add in a time for goschedular to allow
|
|
// routine to actually wait on the forAlert and kick channels
|
|
select {
|
|
case <-check:
|
|
t.Fatal("leaky waiter")
|
|
default:
|
|
}
|
|
}
|