Merge pull request #2889 from hashicorp/f-parallel-api

Parallel API tests
This commit is contained in:
Alex Dadgar 2017-07-21 18:05:23 -07:00 committed by GitHub
commit e9a1397f34
15 changed files with 78 additions and 0 deletions

View File

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

View File

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

View File

@ -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()

View File

@ -8,6 +8,7 @@ import (
)
func TestCompose(t *testing.T) {
t.Parallel()
// Compose a task
task := NewTask("task1", "exec").
SetConfig("foo", "bar").

View File

@ -6,6 +6,7 @@ import (
)
func TestCompose_Constraints(t *testing.T) {
t.Parallel()
c := NewConstraint("kernel.name", "=", "darwin")
expect := &Constraint{
LTarget: "kernel.name",

View File

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

View File

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

View File

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

View File

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

View File

@ -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()

View File

@ -8,6 +8,7 @@ import (
)
func TestRegionsList(t *testing.T) {
t.Parallel()
c1, s1 := makeClient(t, nil, func(c *testutil.TestServerConfig) {
c.Region = "regionA"
})

View File

@ -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()

View File

@ -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()

View File

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

View File

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