diff --git a/engine/remote_test.go b/engine/remote_test.go index e59ac78cc0..1563660c97 100644 --- a/engine/remote_test.go +++ b/engine/remote_test.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" "github.com/dotcloud/docker/pkg/beam" + "github.com/dotcloud/docker/pkg/testutils" "io" "strings" "testing" @@ -143,21 +144,7 @@ func testRemote(t *testing.T, senderSide, receiverSide func(*Engine)) { receiverSide(receiver.Engine) go receiver.Run() - timeout(t, func() { + testutils.Timeout(t, func() { senderSide(eng) }) } - -func timeout(t *testing.T, f func()) { - onTimeout := time.After(100 * time.Millisecond) - onDone := make(chan bool) - go func() { - f() - close(onDone) - }() - select { - case <-onTimeout: - t.Fatalf("timeout") - case <-onDone: - } -} diff --git a/integration-cli/MAINTAINERS b/integration-cli/MAINTAINERS index 53c8a11858..6dde4769d7 100644 --- a/integration-cli/MAINTAINERS +++ b/integration-cli/MAINTAINERS @@ -1 +1 @@ -Cristian Staretu (github: unclejack) +Cristian Staretu (@unclejack) diff --git a/pkg/testutils/MAINTAINERS b/pkg/testutils/MAINTAINERS new file mode 100644 index 0000000000..f2e8c52e51 --- /dev/null +++ b/pkg/testutils/MAINTAINERS @@ -0,0 +1,2 @@ +Solomon Hykes (@shykes) +Cristian Staretu (@unclejack) diff --git a/pkg/testutils/README.md b/pkg/testutils/README.md new file mode 100644 index 0000000000..a208a90e68 --- /dev/null +++ b/pkg/testutils/README.md @@ -0,0 +1,2 @@ +`testutils` is a collection of utility functions to facilitate the writing +of tests. It is used in various places by the Docker test suite. diff --git a/pkg/testutils/testutils.go b/pkg/testutils/testutils.go new file mode 100644 index 0000000000..4655e5844d --- /dev/null +++ b/pkg/testutils/testutils.go @@ -0,0 +1,23 @@ +package testutils + +import ( + "testing" + "time" +) + +// Timeout calls f and waits for 100ms for it to complete. +// If it doesn't, it causes the tests to fail. +// t must be a valid testing context. +func Timeout(t *testing.T, f func()) { + onTimeout := time.After(100 * time.Millisecond) + onDone := make(chan bool) + go func() { + f() + close(onDone) + }() + select { + case <-onTimeout: + t.Fatalf("timeout") + case <-onDone: + } +}