From ffda9d71d464adc6414734c8728c76a395bb2eb0 Mon Sep 17 00:00:00 2001 From: Chris Hines Date: Tue, 24 Nov 2015 15:12:31 -0500 Subject: [PATCH] Speed up tests by allowing parallel execution. --- client/driver/docker_test.go | 13 +++++++++++++ client/driver/driver_test.go | 3 +++ client/driver/exec_test.go | 7 +++++++ client/driver/executor/exec_basic_test.go | 1 + client/driver/executor/exec_linux_test.go | 1 + client/driver/java_test.go | 4 ++++ client/driver/qemu_test.go | 3 +++ client/driver/raw_exec_test.go | 7 +++++++ 8 files changed, 39 insertions(+) diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 40ce7597065..2213ecaefc6 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -119,6 +119,7 @@ func dockerSetup(t *testing.T, task *structs.Task) (*docker.Client, DriverHandle } func TestDockerDriver_Handle(t *testing.T) { + t.Parallel() h := &DockerHandle{ imageID: "imageid", containerID: "containerid", @@ -135,6 +136,7 @@ func TestDockerDriver_Handle(t *testing.T) { // This test should always pass, even if docker daemon is not available func TestDockerDriver_Fingerprint(t *testing.T) { + t.Parallel() d := NewDockerDriver(testDockerDriverContext("")) node := &structs.Node{ Attributes: make(map[string]string), @@ -153,6 +155,7 @@ func TestDockerDriver_Fingerprint(t *testing.T) { } func TestDockerDriver_StartOpen_Wait(t *testing.T) { + t.Parallel() if !dockerIsConnected(t) { t.SkipNow() } @@ -190,6 +193,7 @@ func TestDockerDriver_StartOpen_Wait(t *testing.T) { } func TestDockerDriver_Start_Wait(t *testing.T) { + t.Parallel() task := &structs.Task{ Name: "redis-demo", Config: map[string]interface{}{ @@ -223,6 +227,7 @@ func TestDockerDriver_Start_Wait(t *testing.T) { } func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) { + t.Parallel() // This test requires that the alloc dir be mounted into docker as a volume. // Because this cannot happen when docker is run remotely, e.g. when running // docker in a VM, we skip this when we detect Docker is being run remotely. @@ -285,6 +290,7 @@ func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) { } func TestDockerDriver_Start_Kill_Wait(t *testing.T) { + t.Parallel() task := &structs.Task{ Name: "redis-demo", Config: map[string]interface{}{ @@ -317,6 +323,7 @@ func TestDockerDriver_Start_Kill_Wait(t *testing.T) { } func TestDocker_StartN(t *testing.T) { + t.Parallel() if !dockerIsConnected(t) { t.SkipNow() } @@ -371,6 +378,7 @@ func TestDocker_StartN(t *testing.T) { } func TestDocker_StartNVersions(t *testing.T) { + t.Parallel() if !dockerIsConnected(t) { t.SkipNow() } @@ -428,6 +436,7 @@ func TestDocker_StartNVersions(t *testing.T) { } func TestDockerHostNet(t *testing.T) { + t.Parallel() expected := "host" task := &structs.Task{ @@ -457,6 +466,7 @@ func TestDockerHostNet(t *testing.T) { } func TestDockerLabels(t *testing.T) { + t.Parallel() task := dockerTask() task.Config["labels"] = []map[string]string{ map[string]string{ @@ -483,6 +493,7 @@ func TestDockerLabels(t *testing.T) { } func TestDockerDNS(t *testing.T) { + t.Parallel() task := dockerTask() task.Config["dns_servers"] = []string{"8.8.8.8", "8.8.4.4"} task.Config["dns_search_domains"] = []string{"example.com", "example.org", "example.net"} @@ -514,6 +525,7 @@ func inSlice(needle string, haystack []string) bool { } func TestDockerPortsNoMap(t *testing.T) { + t.Parallel() task := dockerTask() client, handle, cleanup := dockerSetup(t, task) @@ -564,6 +576,7 @@ func TestDockerPortsNoMap(t *testing.T) { } func TestDockerPortsMapping(t *testing.T) { + t.Parallel() task := dockerTask() task.Config["port_map"] = []map[string]string{ map[string]string{ diff --git a/client/driver/driver_test.go b/client/driver/driver_test.go index c23111462bc..e35c5c5ad05 100644 --- a/client/driver/driver_test.go +++ b/client/driver/driver_test.go @@ -61,6 +61,7 @@ func testDriverExecContext(task *structs.Task, driverCtx *DriverContext) *ExecCo } func TestDriver_TaskEnvironmentVariables(t *testing.T) { + t.Parallel() ctx := &ExecContext{} task := &structs.Task{ Env: map[string]string{ @@ -108,6 +109,7 @@ func TestDriver_TaskEnvironmentVariables(t *testing.T) { } func TestMapMergeStrInt(t *testing.T) { + t.Parallel() a := map[string]int{ "cakes": 5, "cookies": 3, @@ -132,6 +134,7 @@ func TestMapMergeStrInt(t *testing.T) { } func TestMapMergeStrStr(t *testing.T) { + t.Parallel() a := map[string]string{ "cake": "chocolate", "cookie": "caramel", diff --git a/client/driver/exec_test.go b/client/driver/exec_test.go index f5470074a39..66795781fee 100644 --- a/client/driver/exec_test.go +++ b/client/driver/exec_test.go @@ -16,6 +16,7 @@ import ( ) func TestExecDriver_Fingerprint(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) d := NewExecDriver(testDriverContext("")) node := &structs.Node{ @@ -34,6 +35,7 @@ func TestExecDriver_Fingerprint(t *testing.T) { } func TestExecDriver_StartOpen_Wait(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) task := &structs.Task{ Name: "sleep", @@ -68,6 +70,7 @@ func TestExecDriver_StartOpen_Wait(t *testing.T) { } func TestExecDriver_Start_Wait(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) task := &structs.Task{ Name: "sleep", @@ -109,6 +112,7 @@ func TestExecDriver_Start_Wait(t *testing.T) { } func TestExecDriver_Start_Artifact_basic(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) file := "hi_linux_amd64" checksum := "sha256:6f99b4c5184726e601ecb062500aeb9537862434dfe1898dbe5c68d9f50c179c" @@ -153,6 +157,7 @@ func TestExecDriver_Start_Artifact_basic(t *testing.T) { } func TestExecDriver_Start_Artifact_expanded(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) file := "hi_linux_amd64" @@ -199,6 +204,7 @@ func TestExecDriver_Start_Artifact_expanded(t *testing.T) { } } func TestExecDriver_Start_Wait_AllocDir(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) exp := []byte{'w', 'i', 'n'} @@ -251,6 +257,7 @@ func TestExecDriver_Start_Wait_AllocDir(t *testing.T) { } func TestExecDriver_Start_Kill_Wait(t *testing.T) { + t.Parallel() ctestutils.ExecCompatible(t) task := &structs.Task{ Name: "sleep", diff --git a/client/driver/executor/exec_basic_test.go b/client/driver/executor/exec_basic_test.go index d9eed49f977..1a829b95db7 100644 --- a/client/driver/executor/exec_basic_test.go +++ b/client/driver/executor/exec_basic_test.go @@ -3,5 +3,6 @@ package executor import "testing" func TestExecutorBasic(t *testing.T) { + t.Parallel() testExecutor(t, NewBasicExecutor, nil) } diff --git a/client/driver/executor/exec_linux_test.go b/client/driver/executor/exec_linux_test.go index 2c48418e12d..6cc2d104cd8 100644 --- a/client/driver/executor/exec_linux_test.go +++ b/client/driver/executor/exec_linux_test.go @@ -13,5 +13,6 @@ func init() { } func TestExecutorLinux(t *testing.T) { + t.Parallel() testExecutor(t, NewLinuxExecutor, ctestutil.ExecCompatible) } diff --git a/client/driver/java_test.go b/client/driver/java_test.go index af6e44d6d8d..5fa47320b4b 100644 --- a/client/driver/java_test.go +++ b/client/driver/java_test.go @@ -19,6 +19,7 @@ func javaLocated() bool { // The fingerprinter test should always pass, even if Java is not installed. func TestJavaDriver_Fingerprint(t *testing.T) { + t.Parallel() ctestutils.JavaCompatible(t) d := NewJavaDriver(testDriverContext("")) node := &structs.Node{ @@ -42,6 +43,7 @@ func TestJavaDriver_Fingerprint(t *testing.T) { } func TestJavaDriver_StartOpen_Wait(t *testing.T) { + t.Parallel() if !javaLocated() { t.Skip("Java not found; skipping") } @@ -88,6 +90,7 @@ func TestJavaDriver_StartOpen_Wait(t *testing.T) { } func TestJavaDriver_Start_Wait(t *testing.T) { + t.Parallel() if !javaLocated() { t.Skip("Java not found; skipping") } @@ -134,6 +137,7 @@ func TestJavaDriver_Start_Wait(t *testing.T) { } func TestJavaDriver_Start_Kill_Wait(t *testing.T) { + t.Parallel() if !javaLocated() { t.Skip("Java not found; skipping") } diff --git a/client/driver/qemu_test.go b/client/driver/qemu_test.go index cecca4357f1..65846203bc6 100644 --- a/client/driver/qemu_test.go +++ b/client/driver/qemu_test.go @@ -12,6 +12,7 @@ import ( // The fingerprinter test should always pass, even if QEMU is not installed. func TestQemuDriver_Fingerprint(t *testing.T) { + t.Parallel() ctestutils.QemuCompatible(t) d := NewQemuDriver(testDriverContext("")) node := &structs.Node{ @@ -33,6 +34,7 @@ func TestQemuDriver_Fingerprint(t *testing.T) { } func TestQemuDriver_StartOpen_Wait(t *testing.T) { + t.Parallel() ctestutils.QemuCompatible(t) // TODO: use test server to load from a fixture task := &structs.Task{ @@ -86,6 +88,7 @@ func TestQemuDriver_StartOpen_Wait(t *testing.T) { } func TestQemuDriver_RequiresMemory(t *testing.T) { + t.Parallel() ctestutils.QemuCompatible(t) // TODO: use test server to load from a fixture task := &structs.Task{ diff --git a/client/driver/raw_exec_test.go b/client/driver/raw_exec_test.go index 0e249d13d12..8d656c9b085 100644 --- a/client/driver/raw_exec_test.go +++ b/client/driver/raw_exec_test.go @@ -17,6 +17,7 @@ import ( ) func TestRawExecDriver_Fingerprint(t *testing.T) { + t.Parallel() d := NewRawExecDriver(testDriverContext("")) node := &structs.Node{ Attributes: make(map[string]string), @@ -51,6 +52,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) { } func TestRawExecDriver_StartOpen_Wait(t *testing.T) { + t.Parallel() task := &structs.Task{ Name: "sleep", Config: map[string]interface{}{ @@ -91,6 +93,7 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) { } func TestRawExecDriver_Start_Artifact_basic(t *testing.T) { + t.Parallel() path := testtask.Path() ts := httptest.NewServer(http.FileServer(http.Dir(filepath.Dir(path)))) defer ts.Close() @@ -138,6 +141,7 @@ func TestRawExecDriver_Start_Artifact_basic(t *testing.T) { } func TestRawExecDriver_Start_Artifact_expanded(t *testing.T) { + t.Parallel() path := testtask.Path() ts := httptest.NewServer(http.FileServer(http.Dir(filepath.Dir(path)))) defer ts.Close() @@ -185,6 +189,7 @@ func TestRawExecDriver_Start_Artifact_expanded(t *testing.T) { } func TestRawExecDriver_Start_Wait(t *testing.T) { + t.Parallel() task := &structs.Task{ Name: "sleep", Config: map[string]interface{}{ @@ -226,6 +231,7 @@ func TestRawExecDriver_Start_Wait(t *testing.T) { } func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) { + t.Parallel() exp := []byte{'w', 'i', 'n'} file := "output.txt" outPath := fmt.Sprintf(`$%s/%s`, environment.AllocDir, file) @@ -278,6 +284,7 @@ func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) { } func TestRawExecDriver_Start_Kill_Wait(t *testing.T) { + t.Parallel() task := &structs.Task{ Name: "sleep", Config: map[string]interface{}{