mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 05:01:28 +00:00
pkg/testutils: utility functions to facilitate writing Go tests
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
+2
-15
@@ -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:
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user