mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-25 12:57:17 +00:00
ethlog: add test that adds log systems concurrently
This commit is contained in:
parent
3b1296077b
commit
d5a7ba1626
@ -3,8 +3,10 @@ package ethlog
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TestLogSystem struct {
|
||||
@ -126,3 +128,30 @@ func TestNoLogSystem(t *testing.T) {
|
||||
logger.Warnln("warn")
|
||||
Flush()
|
||||
}
|
||||
|
||||
func TestConcurrentAddSystem(t *testing.T) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
Reset()
|
||||
|
||||
logger := NewLogger("TEST")
|
||||
stop := make(chan struct{})
|
||||
writer := func() {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
default:
|
||||
logger.Infof("foo")
|
||||
Flush()
|
||||
}
|
||||
}
|
||||
|
||||
go writer()
|
||||
go writer()
|
||||
|
||||
stopTime := time.Now().Add(100 * time.Millisecond)
|
||||
for time.Now().Before(stopTime) {
|
||||
time.Sleep(time.Duration(rand.Intn(20)) * time.Millisecond)
|
||||
AddLogSystem(&TestLogSystem{level: InfoLevel})
|
||||
}
|
||||
close(stop)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user