ethlog: add test that adds log systems concurrently
This commit is contained in:
parent
3b1296077b
commit
d5a7ba1626
@ -3,8 +3,10 @@ package ethlog
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestLogSystem struct {
|
type TestLogSystem struct {
|
||||||
@ -126,3 +128,30 @@ func TestNoLogSystem(t *testing.T) {
|
|||||||
logger.Warnln("warn")
|
logger.Warnln("warn")
|
||||||
Flush()
|
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