1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon/logger/loggerutils: add TestFollowLogsClose

This test case checks that followLogs() exits once the reader is gone.
Currently it does not (i.e. this test is supposed to fail) due to #37391.

[kolyshkin@: test case Brian Goff, changelog and all bugs are by me]
Source: https://gist.github.com/cpuguy83/e538793de18c762608358ee0eaddc197

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Brian Goff 2018-08-27 13:53:23 -07:00 committed by Kir Kolyshkin
parent 2e4c2a6bf9
commit d37a11bfba

View file

@ -4,6 +4,8 @@ import (
"bufio" "bufio"
"context" "context"
"io" "io"
"io/ioutil"
"os"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -74,3 +76,44 @@ func TestTailFiles(t *testing.T) {
assert.Assert(t, string(msg.Line) == "Where we're going we don't need roads.", string(msg.Line)) assert.Assert(t, string(msg.Line) == "Where we're going we don't need roads.", string(msg.Line))
} }
} }
func TestFollowLogsClose(t *testing.T) {
lw := logger.NewLogWatcher()
f, err := ioutil.TempFile("", t.Name())
assert.NilError(t, err)
defer func() {
f.Close()
os.Remove(f.Name())
}()
makeDecoder := func(rdr io.Reader) func() (*logger.Message, error) {
return func() (*logger.Message, error) {
return &logger.Message{}, nil
}
}
followLogsDone := make(chan struct{})
var since, until time.Time
go func() {
followLogs(f, lw, make(chan interface{}), makeDecoder, since, until)
close(followLogsDone)
}()
select {
case <-lw.Msg:
case err := <-lw.Err:
assert.NilError(t, err)
case <-followLogsDone:
t.Fatal("follow logs finished unexpectedly")
case <-time.After(10 * time.Second):
t.Fatal("timeout waiting for log message")
}
lw.Close()
select {
case <-followLogsDone:
case <-time.After(20 * time.Second):
t.Fatal("timeout waiting for followLogs() to finish")
}
}