diff --git a/api/agent_test.go b/api/agent_test.go index b240a3438..82ea3b5a1 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -9,6 +9,7 @@ import ( ) func TestAgent_Self(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() @@ -33,6 +34,7 @@ func TestAgent_Self(t *testing.T) { } func TestAgent_NodeName(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Agent() @@ -48,6 +50,7 @@ func TestAgent_NodeName(t *testing.T) { } func TestAgent_Datacenter(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Agent() @@ -63,6 +66,7 @@ func TestAgent_Datacenter(t *testing.T) { } func TestAgent_Join(t *testing.T) { + t.Parallel() c1, s1 := makeClient(t, nil, nil) defer s1.Stop() a1 := c1.Agent() @@ -92,6 +96,7 @@ func TestAgent_Join(t *testing.T) { } func TestAgent_Members(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Agent() @@ -112,6 +117,7 @@ func TestAgent_Members(t *testing.T) { } func TestAgent_ForceLeave(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Agent() @@ -129,6 +135,7 @@ func (a *AgentMember) String() string { } func TestAgents_Sort(t *testing.T) { + t.Parallel() var sortTests = []struct { in []*AgentMember out []*AgentMember diff --git a/api/allocations_test.go b/api/allocations_test.go index 955ba4644..ba0ab9663 100644 --- a/api/allocations_test.go +++ b/api/allocations_test.go @@ -7,6 +7,7 @@ import ( ) func TestAllocations_List(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Allocations() @@ -53,6 +54,7 @@ func TestAllocations_List(t *testing.T) { } func TestAllocations_PrefixList(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() a := c.Allocations() @@ -100,6 +102,7 @@ func TestAllocations_PrefixList(t *testing.T) { } func TestAllocations_CreateIndexSort(t *testing.T) { + t.Parallel() allocs := []*AllocationListStub{ &AllocationListStub{CreateIndex: 2}, &AllocationListStub{CreateIndex: 1}, diff --git a/api/api_test.go b/api/api_test.go index 5c6ea9e90..06eba83b3 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -43,6 +43,7 @@ func makeClient(t *testing.T, cb1 configCallback, } func TestRequestTime(t *testing.T) { + t.Parallel() srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { time.Sleep(100 * time.Millisecond) d, err := json.Marshal(struct{ Done bool }{true}) @@ -90,6 +91,7 @@ func TestRequestTime(t *testing.T) { } func TestDefaultConfig_env(t *testing.T) { + t.Parallel() url := "http://1.2.3.4:5678" auth := []string{"nomaduser", "12345"} @@ -115,6 +117,7 @@ func TestDefaultConfig_env(t *testing.T) { } func TestSetQueryOptions(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() @@ -142,6 +145,7 @@ func TestSetQueryOptions(t *testing.T) { } func TestSetWriteOptions(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() @@ -157,6 +161,7 @@ func TestSetWriteOptions(t *testing.T) { } func TestRequestToHTTP(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() @@ -179,6 +184,7 @@ func TestRequestToHTTP(t *testing.T) { } func TestParseQueryMeta(t *testing.T) { + t.Parallel() resp := &http.Response{ Header: make(map[string][]string), } @@ -203,6 +209,7 @@ func TestParseQueryMeta(t *testing.T) { } func TestParseWriteMeta(t *testing.T) { + t.Parallel() resp := &http.Response{ Header: make(map[string][]string), } @@ -219,6 +226,7 @@ func TestParseWriteMeta(t *testing.T) { } func TestQueryString(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() diff --git a/api/compose_test.go b/api/compose_test.go index ef24f2e99..40dd55090 100644 --- a/api/compose_test.go +++ b/api/compose_test.go @@ -8,6 +8,7 @@ import ( ) func TestCompose(t *testing.T) { + t.Parallel() // Compose a task task := NewTask("task1", "exec"). SetConfig("foo", "bar"). diff --git a/api/constraint_test.go b/api/constraint_test.go index 26b0c9fcf..c619c0153 100644 --- a/api/constraint_test.go +++ b/api/constraint_test.go @@ -6,6 +6,7 @@ import ( ) func TestCompose_Constraints(t *testing.T) { + t.Parallel() c := NewConstraint("kernel.name", "=", "darwin") expect := &Constraint{ LTarget: "kernel.name", diff --git a/api/evaluations_test.go b/api/evaluations_test.go index 017ea3732..0ec17be3c 100644 --- a/api/evaluations_test.go +++ b/api/evaluations_test.go @@ -8,6 +8,7 @@ import ( ) func TestEvaluations_List(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() e := c.Evaluations() @@ -49,6 +50,7 @@ func TestEvaluations_List(t *testing.T) { } func TestEvaluations_PrefixList(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() e := c.Evaluations() @@ -88,6 +90,7 @@ func TestEvaluations_PrefixList(t *testing.T) { } func TestEvaluations_Info(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() e := c.Evaluations() @@ -121,6 +124,7 @@ func TestEvaluations_Info(t *testing.T) { } func TestEvaluations_Allocations(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() e := c.Evaluations() @@ -139,6 +143,7 @@ func TestEvaluations_Allocations(t *testing.T) { } func TestEvaluations_Sort(t *testing.T) { + t.Parallel() evals := []*Evaluation{ &Evaluation{CreateIndex: 2}, &Evaluation{CreateIndex: 1}, diff --git a/api/fs_test.go b/api/fs_test.go index bea8d5984..09f5f9073 100644 --- a/api/fs_test.go +++ b/api/fs_test.go @@ -8,6 +8,7 @@ import ( ) func TestFS_FrameReader(t *testing.T) { + t.Parallel() // Create a channel of the frames and a cancel channel framesCh := make(chan *StreamFrame, 3) cancelCh := make(chan struct{}) @@ -76,6 +77,7 @@ func TestFS_FrameReader(t *testing.T) { } func TestFS_FrameReader_Unblock(t *testing.T) { + t.Parallel() // Create a channel of the frames and a cancel channel framesCh := make(chan *StreamFrame, 3) cancelCh := make(chan struct{}) diff --git a/api/jobs_test.go b/api/jobs_test.go index 89d4ee313..a0b214069 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -13,6 +13,7 @@ import ( ) func TestJobs_Register(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -54,6 +55,7 @@ func TestJobs_Register(t *testing.T) { } func TestJobs_Validate(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -81,6 +83,7 @@ func TestJobs_Validate(t *testing.T) { } func TestJobs_Canonicalize(t *testing.T) { + t.Parallel() testCases := []struct { name string expected *Job @@ -589,6 +592,7 @@ func TestJobs_Canonicalize(t *testing.T) { } func TestJobs_EnforceRegister(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -657,6 +661,7 @@ func TestJobs_EnforceRegister(t *testing.T) { } func TestJobs_Revert(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -706,6 +711,7 @@ func TestJobs_Revert(t *testing.T) { } func TestJobs_Info(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -739,6 +745,7 @@ func TestJobs_Info(t *testing.T) { } func TestJobs_Versions(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -771,6 +778,7 @@ func TestJobs_Versions(t *testing.T) { } func TestJobs_PrefixList(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -809,6 +817,7 @@ func TestJobs_PrefixList(t *testing.T) { } func TestJobs_List(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -847,6 +856,7 @@ func TestJobs_List(t *testing.T) { } func TestJobs_Allocations(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -868,6 +878,7 @@ func TestJobs_Allocations(t *testing.T) { } func TestJobs_Evaluations(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -909,6 +920,7 @@ func TestJobs_Evaluations(t *testing.T) { } func TestJobs_Deregister(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -968,6 +980,7 @@ func TestJobs_Deregister(t *testing.T) { } func TestJobs_ForceEvaluate(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -1007,6 +1020,7 @@ func TestJobs_ForceEvaluate(t *testing.T) { } func TestJobs_PeriodicForce(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -1059,6 +1073,7 @@ func TestJobs_PeriodicForce(t *testing.T) { } func TestJobs_Plan(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -1129,6 +1144,7 @@ func TestJobs_Plan(t *testing.T) { } func TestJobs_JobSummary(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() jobs := c.Jobs() @@ -1166,6 +1182,7 @@ func TestJobs_JobSummary(t *testing.T) { } func TestJobs_NewBatchJob(t *testing.T) { + t.Parallel() job := NewBatchJob("job1", "myjob", "region1", 5) expect := &Job{ Region: helper.StringToPtr("region1"), @@ -1180,6 +1197,7 @@ func TestJobs_NewBatchJob(t *testing.T) { } func TestJobs_NewServiceJob(t *testing.T) { + t.Parallel() job := NewServiceJob("job1", "myjob", "region1", 5) expect := &Job{ Region: helper.StringToPtr("region1"), @@ -1194,6 +1212,7 @@ func TestJobs_NewServiceJob(t *testing.T) { } func TestJobs_SetMeta(t *testing.T) { + t.Parallel() job := &Job{Meta: nil} // Initializes a nil map @@ -1216,6 +1235,7 @@ func TestJobs_SetMeta(t *testing.T) { } func TestJobs_Constrain(t *testing.T) { + t.Parallel() job := &Job{Constraints: nil} // Create and add a constraint @@ -1249,6 +1269,7 @@ func TestJobs_Constrain(t *testing.T) { } func TestJobs_Sort(t *testing.T) { + t.Parallel() jobs := []*JobListStub{ &JobListStub{ID: "job2"}, &JobListStub{ID: "job0"}, diff --git a/api/nodes_test.go b/api/nodes_test.go index aa74c7510..562da6324 100644 --- a/api/nodes_test.go +++ b/api/nodes_test.go @@ -12,6 +12,7 @@ import ( ) func TestNodes_List(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.DevMode = true }) @@ -40,6 +41,7 @@ func TestNodes_List(t *testing.T) { } func TestNodes_PrefixList(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.DevMode = true }) @@ -80,6 +82,7 @@ func TestNodes_PrefixList(t *testing.T) { } func TestNodes_Info(t *testing.T) { + t.Parallel() startTime := time.Now().Unix() c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.DevMode = true @@ -131,6 +134,7 @@ func TestNodes_Info(t *testing.T) { } func TestNodes_ToggleDrain(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.DevMode = true }) @@ -196,6 +200,7 @@ func TestNodes_ToggleDrain(t *testing.T) { } func TestNodes_Allocations(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() nodes := c.Nodes() @@ -214,6 +219,7 @@ func TestNodes_Allocations(t *testing.T) { } func TestNodes_ForceEvaluate(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.DevMode = true }) @@ -252,6 +258,7 @@ func TestNodes_ForceEvaluate(t *testing.T) { } func TestNodes_Sort(t *testing.T) { + t.Parallel() nodes := []*NodeListStub{ &NodeListStub{CreateIndex: 2}, &NodeListStub{CreateIndex: 1}, diff --git a/api/operator_test.go b/api/operator_test.go index 4db2c4c45..004cb64a7 100644 --- a/api/operator_test.go +++ b/api/operator_test.go @@ -6,6 +6,7 @@ import ( ) func TestOperator_RaftGetConfiguration(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() @@ -22,6 +23,7 @@ func TestOperator_RaftGetConfiguration(t *testing.T) { } func TestOperator_RaftRemovePeerByAddress(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() diff --git a/api/regions_test.go b/api/regions_test.go index d35e7fc59..502ab4525 100644 --- a/api/regions_test.go +++ b/api/regions_test.go @@ -8,6 +8,7 @@ import ( ) func TestRegionsList(t *testing.T) { + t.Parallel() c1, s1 := makeClient(t, nil, func(c *testutil.TestServerConfig) { c.Region = "regionA" }) diff --git a/api/status_test.go b/api/status_test.go index fb100018b..ab48ad203 100644 --- a/api/status_test.go +++ b/api/status_test.go @@ -5,6 +5,7 @@ import ( ) func TestStatus_Leader(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() status := c.Status() diff --git a/api/system_test.go b/api/system_test.go index 430332417..cc24615fa 100644 --- a/api/system_test.go +++ b/api/system_test.go @@ -5,6 +5,7 @@ import ( ) func TestSystem_GarbageCollect(t *testing.T) { + t.Parallel() c, s := makeClient(t, nil, nil) defer s.Stop() e := c.System() diff --git a/api/tasks_test.go b/api/tasks_test.go index 334a1cdf3..cf639e3dc 100644 --- a/api/tasks_test.go +++ b/api/tasks_test.go @@ -8,6 +8,7 @@ import ( ) func TestTaskGroup_NewTaskGroup(t *testing.T) { + t.Parallel() grp := NewTaskGroup("grp1", 2) expect := &TaskGroup{ Name: helper.StringToPtr("grp1"), @@ -19,6 +20,7 @@ func TestTaskGroup_NewTaskGroup(t *testing.T) { } func TestTaskGroup_Constrain(t *testing.T) { + t.Parallel() grp := NewTaskGroup("grp1", 1) // Add a constraint to the group @@ -52,6 +54,7 @@ func TestTaskGroup_Constrain(t *testing.T) { } func TestTaskGroup_SetMeta(t *testing.T) { + t.Parallel() grp := NewTaskGroup("grp1", 1) // Initializes an empty map @@ -74,6 +77,7 @@ func TestTaskGroup_SetMeta(t *testing.T) { } func TestTaskGroup_AddTask(t *testing.T) { + t.Parallel() grp := NewTaskGroup("grp1", 1) // Add the task to the task group @@ -105,6 +109,7 @@ func TestTaskGroup_AddTask(t *testing.T) { } func TestTask_NewTask(t *testing.T) { + t.Parallel() task := NewTask("task1", "exec") expect := &Task{ Name: "task1", @@ -116,6 +121,7 @@ func TestTask_NewTask(t *testing.T) { } func TestTask_SetConfig(t *testing.T) { + t.Parallel() task := NewTask("task1", "exec") // Initializes an empty map @@ -138,6 +144,7 @@ func TestTask_SetConfig(t *testing.T) { } func TestTask_SetMeta(t *testing.T) { + t.Parallel() task := NewTask("task1", "exec") // Initializes an empty map @@ -160,6 +167,7 @@ func TestTask_SetMeta(t *testing.T) { } func TestTask_Require(t *testing.T) { + t.Parallel() task := NewTask("task1", "exec") // Create some require resources @@ -188,6 +196,7 @@ func TestTask_Require(t *testing.T) { } func TestTask_Constrain(t *testing.T) { + t.Parallel() task := NewTask("task1", "exec") // Add a constraint to the task @@ -221,6 +230,7 @@ func TestTask_Constrain(t *testing.T) { } func TestTask_Artifact(t *testing.T) { + t.Parallel() a := TaskArtifact{ GetterSource: helper.StringToPtr("http://localhost/foo.txt"), GetterMode: helper.StringToPtr("file"), diff --git a/testutil/server.go b/testutil/server.go index bf2a0017d..3428c107d 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -132,6 +132,14 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer { t.Skipf("nomad not found, skipping: %v", err) } + // Do a sanity check that we are actually running nomad + vcmd := exec.Command(path, "-version") + vcmd.Stdout = nil + vcmd.Stderr = nil + if err := vcmd.Run(); err != nil { + t.Skipf("nomad version failed. Did you run your test with -tags nomad_test (%v)", err) + } + dataDir, err := ioutil.TempDir("", "nomad") if err != nil { t.Fatalf("err: %s", err)