Speed up tests by allowing parallel execution.

This commit is contained in:
Chris Hines 2015-11-24 15:12:31 -05:00
parent 5b2168bb12
commit 37745f66c9
8 changed files with 39 additions and 0 deletions

View File

@ -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{

View File

@ -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",

View File

@ -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",

View File

@ -3,5 +3,6 @@ package executor
import "testing"
func TestExecutorBasic(t *testing.T) {
t.Parallel()
testExecutor(t, NewBasicExecutor, nil)
}

View File

@ -13,5 +13,6 @@ func init() {
}
func TestExecutorLinux(t *testing.T) {
t.Parallel()
testExecutor(t, NewLinuxExecutor, ctestutil.ExecCompatible)
}

View File

@ -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")
}

View File

@ -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{

View File

@ -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{}{