Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 70b230e

Browse files
samuelkarpthaJeztah
authored andcommitted
awslogs: fix flaky TestLogBlocking unit test
TestLogBlocking is intended to test that the Log method blocks by default. It does this by mocking out the internals of the awslogs.logStream and replacing one of its internal channels with one that is controlled by the test. The call to Log occurs inside a goroutine. Go may or may not schedule the goroutine immediately and the blocking may or may not be observed outside the goroutine immediately due to decisions made by the Go runtime. This change adds a small timeout for test failure so that the Go runtime has the opportunity to run the goroutine before the test fails. Signed-off-by: Samuel Karp <skarp@amazon.com> (cherry picked from commit fd94bae0b8acc451a79667dd1cef4c583d532187) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 183cac25f9804ba2e215ab1518d2ae1275f35dbd Component: engine
1 parent 9bf9def commit 70b230e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

components/engine/daemon/logger/awslogs/cloudwatchlogs_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/docker/docker/dockerversion"
2525
"gotest.tools/assert"
2626
is "gotest.tools/assert/cmp"
27-
"gotest.tools/skip"
2827
)
2928

3029
const (
@@ -286,8 +285,10 @@ func TestLogClosed(t *testing.T) {
286285
}
287286
}
288287

288+
// TestLogBlocking tests that the Log method blocks appropriately when
289+
// non-blocking behavior is not enabled. Blocking is achieved through an
290+
// internal channel that must be drained for Log to return.
289291
func TestLogBlocking(t *testing.T) {
290-
skip.If(t, runtime.GOOS == "windows", "FIXME: test is flaky on Windows. See #39857")
291292
mockClient := newMockClient()
292293
stream := &logStream{
293294
client: mockClient,
@@ -301,18 +302,20 @@ func TestLogBlocking(t *testing.T) {
301302
err := stream.Log(&logger.Message{})
302303
errorCh <- err
303304
}()
305+
// block until the goroutine above has started
304306
<-started
305307
select {
306308
case err := <-errorCh:
307309
t.Fatal("Expected stream.Log to block: ", err)
308310
default:
309-
break
310311
}
312+
// assuming it is blocked, we can now try to drain the internal channel and
313+
// unblock it
311314
select {
312-
case <-stream.messages:
313-
break
314-
default:
315+
case <-time.After(10 * time.Millisecond):
316+
// if we're unable to drain the channel within 10ms, something seems broken
315317
t.Fatal("Expected to be able to read from stream.messages but was unable to")
318+
case <-stream.messages:
316319
}
317320
select {
318321
case err := <-errorCh:

0 commit comments

Comments
 (0)