From 0311fdd2c0039b742b8eb091bdaf2296fc618c87 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 9 May 2014 21:11:24 -0700 Subject: [PATCH 1/3] pkg/testutils: utility functions to facilitate writing Go tests Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: ca231b3de52f718d96c0ff6e7af40c7c0fade623 Component: engine --- components/engine/engine/remote_test.go | 17 ++------------- components/engine/pkg/testutils/MAINTAINERS | 1 + components/engine/pkg/testutils/README.md | 2 ++ components/engine/pkg/testutils/testutils.go | 23 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 components/engine/pkg/testutils/MAINTAINERS create mode 100644 components/engine/pkg/testutils/README.md create mode 100644 components/engine/pkg/testutils/testutils.go diff --git a/components/engine/engine/remote_test.go b/components/engine/engine/remote_test.go index e59ac78cc0..1563660c97 100644 --- a/components/engine/engine/remote_test.go +++ b/components/engine/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/components/engine/pkg/testutils/MAINTAINERS b/components/engine/pkg/testutils/MAINTAINERS new file mode 100644 index 0000000000..012d27a2e0 --- /dev/null +++ b/components/engine/pkg/testutils/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes (@shykes) diff --git a/components/engine/pkg/testutils/README.md b/components/engine/pkg/testutils/README.md new file mode 100644 index 0000000000..a208a90e68 --- /dev/null +++ b/components/engine/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/components/engine/pkg/testutils/testutils.go b/components/engine/pkg/testutils/testutils.go new file mode 100644 index 0000000000..4655e5844d --- /dev/null +++ b/components/engine/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: + } +} From c0015f4cf44987701ba005c70d5923eaf1f32f55 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 2 Jun 2014 07:01:17 +0000 Subject: [PATCH 2/3] Add Cristian as maintainer to pkg/testutils Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: 1a93d3b054751f6783064e5adb91f196687400b2 Component: engine --- components/engine/pkg/testutils/MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/pkg/testutils/MAINTAINERS b/components/engine/pkg/testutils/MAINTAINERS index 012d27a2e0..1c41a67440 100644 --- a/components/engine/pkg/testutils/MAINTAINERS +++ b/components/engine/pkg/testutils/MAINTAINERS @@ -1 +1,2 @@ Solomon Hykes (@shykes) +Cristian Staretu (github: unclejack) From d8a617a361139bd2ff39923fd16639f2aeb52c7d Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 2 Jun 2014 07:05:06 +0000 Subject: [PATCH 3/3] Fix format in maintainers files Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: 0a06e9bd91faff2c129fd5a7b30b85351c96601f Component: engine --- components/engine/integration-cli/MAINTAINERS | 2 +- components/engine/pkg/testutils/MAINTAINERS | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/integration-cli/MAINTAINERS b/components/engine/integration-cli/MAINTAINERS index 53c8a11858..6dde4769d7 100644 --- a/components/engine/integration-cli/MAINTAINERS +++ b/components/engine/integration-cli/MAINTAINERS @@ -1 +1 @@ -Cristian Staretu (github: unclejack) +Cristian Staretu (@unclejack) diff --git a/components/engine/pkg/testutils/MAINTAINERS b/components/engine/pkg/testutils/MAINTAINERS index 1c41a67440..f2e8c52e51 100644 --- a/components/engine/pkg/testutils/MAINTAINERS +++ b/components/engine/pkg/testutils/MAINTAINERS @@ -1,2 +1,2 @@ Solomon Hykes (@shykes) -Cristian Staretu (github: unclejack) +Cristian Staretu (@unclejack)