diff options
author | Felix Lange <fjl@twurst.com> | 2014-10-15 01:07:54 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2014-10-17 23:20:44 +0800 |
commit | a6265cb49a0fd5641e53ed8cc8505bb91cb88976 (patch) | |
tree | a931830e997cb85ad483f5f6c4f1737e5ef760ec | |
parent | 793baf060a0e918b5d5ca72a425c99751b93ab41 (diff) | |
download | go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar.gz go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar.bz2 go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar.lz go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar.xz go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.tar.zst go-tangerine-a6265cb49a0fd5641e53ed8cc8505bb91cb88976.zip |
ethlog: verify that Flush is blocking in TestLoggerFlush
-rw-r--r-- | ethlog/loggers_test.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/ethlog/loggers_test.go b/ethlog/loggers_test.go index ffc30e21f..0466a3d59 100644 --- a/ethlog/loggers_test.go +++ b/ethlog/loggers_test.go @@ -49,22 +49,40 @@ func (ls *TestLogSystem) CheckOutput(t *testing.T, expected string) { } } +type blockedLogSystem struct { + LogSystem + unblock chan struct{} +} + +func (ls blockedLogSystem) Println(v ...interface{}) { + <-ls.unblock + ls.LogSystem.Println(v...) +} + +func (ls blockedLogSystem) Printf(fmt string, v ...interface{}) { + <-ls.unblock + ls.LogSystem.Printf(fmt, v...) } func TestLoggerFlush(t *testing.T) { Reset() logger := NewLogger("TEST") - testLogSystem := &TestLogSystem{level: WarnLevel} - AddLogSystem(testLogSystem) + ls := blockedLogSystem{&TestLogSystem{level: WarnLevel}, make(chan struct{})} + AddLogSystem(ls) for i := 0; i < 5; i++ { + // these writes shouldn't hang even though ls is blocked logger.Errorf(".") } - Flush() - output := testLogSystem.Output - if output != "[TEST] .[TEST] .[TEST] .[TEST] .[TEST] ." { - t.Error("Expected complete logger output '[TEST] .[TEST] .[TEST] .[TEST] .[TEST] .', got ", output) + + beforeFlush := time.Now() + time.AfterFunc(80*time.Millisecond, func() { close(ls.unblock) }) + Flush() // this should hang for approx. 80ms + if blockd := time.Now().Sub(beforeFlush); blockd < 80*time.Millisecond { + t.Errorf("Flush didn't block long enough, blocked for %v, should've been >= 80ms", blockd) } + + ls.LogSystem.(*TestLogSystem).CheckOutput(t, "[TEST] .[TEST] .[TEST] .[TEST] .[TEST] .") } func TestLoggerPrintln(t *testing.T) { |