aboutsummaryrefslogtreecommitdiffstats
path: root/ethlog/loggers_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-14 20:35:16 +0800
committerFelix Lange <fjl@twurst.com>2014-10-17 23:20:44 +0800
commitd5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9 (patch)
treea0195da37639f91278f150b5beb70cb4e41b7f2f /ethlog/loggers_test.go
parent3b1296077b2f814bf4bf478aea63503d18ece86f (diff)
downloaddexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.gz
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.bz2
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.lz
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.xz
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.tar.zst
dexon-d5a7ba1626b9c7bbc5733a44fbda2ed50070c1b9.zip
ethlog: add test that adds log systems concurrently
Diffstat (limited to 'ethlog/loggers_test.go')
-rw-r--r--ethlog/loggers_test.go29
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)
+}