From 68278b66c5294690d051d6a0fe157e2b965d7b1a Mon Sep 17 00:00:00 2001 From: Robert Obryk Date: Fri, 29 Mar 2013 22:09:25 +0100 Subject: [PATCH] Added a timeout to TestCmdStreamLargeStderr. --- archive_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/archive_test.go b/archive_test.go index 35185628a5..f583604497 100644 --- a/archive_test.go +++ b/archive_test.go @@ -6,19 +6,27 @@ import ( "os" "os/exec" "testing" + "time" ) func TestCmdStreamLargeStderr(t *testing.T) { - // This test checks for deadlock; thus, the main failure mode of this test is deadlocking. - // FIXME implement a timeout to avoid blocking the whole test suite when this test fails cmd := exec.Command("/bin/sh", "-c", "dd if=/dev/zero bs=1k count=1000 of=/dev/stderr; echo hello") out, err := CmdStream(cmd) if err != nil { t.Fatalf("Failed to start command: " + err.Error()) } - _, err = io.Copy(ioutil.Discard, out) - if err != nil { - t.Fatalf("Command should not have failed (err=%s...)", err.Error()[:100]) + errCh := make(chan error) + go func() { + _, err := io.Copy(ioutil.Discard, out) + errCh <- err + }() + select { + case err := <-errCh: + if err != nil { + t.Fatalf("Command should not have failed (err=%s...)", err.Error()[:100]) + } + case <-time.After(5 * time.Second): + t.Fatalf("Command did not complete in 5 seconds; probable deadlock") } }