Skip to content

Commit

Permalink
Merge pull request moby#39968 from samuelkarp/issue-39857
Browse files Browse the repository at this point in the history
awslogs: fix flaky TestLogBlocking unit test
  • Loading branch information
kolyshkin authored Sep 23, 2019
2 parents 611c8fa + fd94bae commit fd5adec
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions daemon/logger/awslogs/cloudwatchlogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/docker/docker/dockerversion"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/skip"
)

const (
Expand Down Expand Up @@ -286,8 +285,10 @@ func TestLogClosed(t *testing.T) {
}
}

// TestLogBlocking tests that the Log method blocks appropriately when
// non-blocking behavior is not enabled. Blocking is achieved through an
// internal channel that must be drained for Log to return.
func TestLogBlocking(t *testing.T) {
skip.If(t, runtime.GOOS == "windows", "FIXME: test is flaky on Windows. See #39857")
mockClient := newMockClient()
stream := &logStream{
client: mockClient,
Expand All @@ -301,18 +302,20 @@ func TestLogBlocking(t *testing.T) {
err := stream.Log(&logger.Message{})
errorCh <- err
}()
// block until the goroutine above has started
<-started
select {
case err := <-errorCh:
t.Fatal("Expected stream.Log to block: ", err)
default:
break
}
// assuming it is blocked, we can now try to drain the internal channel and
// unblock it
select {
case <-stream.messages:
break
default:
case <-time.After(10 * time.Millisecond):
// if we're unable to drain the channel within 10ms, something seems broken
t.Fatal("Expected to be able to read from stream.messages but was unable to")
case <-stream.messages:
}
select {
case err := <-errorCh:
Expand Down

0 comments on commit fd5adec

Please sign in to comment.