diff --git a/ethlog/loggers_test.go b/ethlog/loggers_test.go index fbfb2c99b3..4c62a0dbd5 100644 --- a/ethlog/loggers_test.go +++ b/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) +}