ethlog: add test that adds log systems concurrently

pull/150/head
Felix Lange 10 years ago
parent 3b1296077b
commit d5a7ba1626
  1. 29
      ethlog/loggers_test.go

@ -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…
Cancel
Save