diff options
author | Felix Lange <fjl@twurst.com> | 2014-10-14 20:35:16 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2014-10-17 23:20:44 +0800 |
commit | d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9 (patch) | |
tree | a0195da37639f91278f150b5beb70cb4e41b7f2f | |
parent | 3b1296077b2f814bf4bf478aea63503d18ece86f (diff) | |
download | go-tangerine-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.gz go-tangerine-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.zst go-tangerine-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.zip |
ethlog: add test that adds log systems concurrently
-rw-r--r-- | ethlog/loggers_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ethlog/loggers_test.go b/ethlog/loggers_test.go index fbfb2c99b..4c62a0dbd 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) +} |