Skip to content

Commit

Permalink
daemon/logger/loggerutils: add TestFollowLogsClose
Browse files Browse the repository at this point in the history
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 moby#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>
(cherry picked from commit d37a11b)

[Conflict due to missing moby commit 94a1015]
  • Loading branch information
cpuguy83 authored and kolyshkin committed Sep 7, 2018
1 parent fff4d4e commit daa54ff
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions daemon/logger/loggerutils/logfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package loggerutils

import (
"io"
"io/ioutil"
"os"
"testing"
"time"

"github.com/docker/docker/daemon/logger"
"gotest.tools/assert"
)

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")
}
}

0 comments on commit daa54ff

Please sign in to comment.