Use new APIs
This commit is contained in:
parent
6ffb801f1e
commit
2efa3bdff8
|
@ -43,7 +43,10 @@ func makeClientWithConfig(
|
|||
cb1(conf)
|
||||
}
|
||||
// Create server
|
||||
server := testutil.NewTestServerConfig(t, cb2)
|
||||
server, err := testutil.NewTestServerConfig(cb2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf.Address = server.HTTPAddr
|
||||
|
||||
// Create client
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestCatalog_Datacenters(t *testing.T) {
|
|||
|
||||
catalog := c.Catalog()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
datacenters, err := catalog.Datacenters()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -25,9 +25,9 @@ func TestCatalog_Datacenters(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Nodes(t *testing.T) {
|
||||
|
@ -36,7 +36,7 @@ func TestCatalog_Nodes(t *testing.T) {
|
|||
|
||||
catalog := c.Catalog()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
nodes, meta, err := catalog.Nodes(nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -55,9 +55,9 @@ func TestCatalog_Nodes(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Nodes_MetaFilter(t *testing.T) {
|
||||
|
@ -70,7 +70,7 @@ func TestCatalog_Nodes_MetaFilter(t *testing.T) {
|
|||
catalog := c.Catalog()
|
||||
|
||||
// Make sure we get the node back when filtering by its metadata
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
nodes, meta, err := catalog.Nodes(&QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -93,12 +93,12 @@ func TestCatalog_Nodes_MetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Get nothing back when we use an invalid filter
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
nodes, meta, err := catalog.Nodes(&QueryOptions{NodeMeta: map[string]string{"nope": "nope"}})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -113,9 +113,9 @@ func TestCatalog_Nodes_MetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Services(t *testing.T) {
|
||||
|
@ -125,7 +125,7 @@ func TestCatalog_Services(t *testing.T) {
|
|||
|
||||
catalog := c.Catalog()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
services, meta, err := catalog.Services(nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -140,9 +140,9 @@ func TestCatalog_Services(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Services_NodeMetaFilter(t *testing.T) {
|
||||
|
@ -155,7 +155,7 @@ func TestCatalog_Services_NodeMetaFilter(t *testing.T) {
|
|||
catalog := c.Catalog()
|
||||
|
||||
// Make sure we get the service back when filtering by the node's metadata
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
services, meta, err := catalog.Services(&QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -170,12 +170,12 @@ func TestCatalog_Services_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Get nothing back when using an invalid filter
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
services, meta, err := catalog.Services(&QueryOptions{NodeMeta: map[string]string{"nope": "nope"}})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -190,9 +190,9 @@ func TestCatalog_Services_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Service(t *testing.T) {
|
||||
|
@ -202,7 +202,7 @@ func TestCatalog_Service(t *testing.T) {
|
|||
|
||||
catalog := c.Catalog()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
services, meta, err := catalog.Service("consul", "", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -217,9 +217,9 @@ func TestCatalog_Service(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Service_NodeMetaFilter(t *testing.T) {
|
||||
|
@ -232,7 +232,7 @@ func TestCatalog_Service_NodeMetaFilter(t *testing.T) {
|
|||
|
||||
catalog := c.Catalog()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
services, meta, err := catalog.Service("consul", "", &QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -247,9 +247,9 @@ func TestCatalog_Service_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Node(t *testing.T) {
|
||||
|
@ -260,7 +260,7 @@ func TestCatalog_Node(t *testing.T) {
|
|||
catalog := c.Catalog()
|
||||
name, _ := c.Agent().NodeName()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
info, meta, err := catalog.Node(name, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -279,9 +279,9 @@ func TestCatalog_Node(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_Registration(t *testing.T) {
|
||||
|
@ -316,7 +316,7 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
Check: check,
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -344,9 +344,9 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test catalog deregistration of the previously registered service
|
||||
dereg := &CatalogDeregistration{
|
||||
|
@ -360,7 +360,7 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
node, _, err := catalog.Node("foobar", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -371,9 +371,9 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test deregistration of the previously registered check
|
||||
dereg = &CatalogDeregistration{
|
||||
|
@ -387,7 +387,7 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
health, _, err := c.Health().Node("foobar", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -398,9 +398,9 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test node deregistration of the previously registered node
|
||||
dereg = &CatalogDeregistration{
|
||||
|
@ -413,7 +413,7 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
node, _, err := catalog.Node("foobar", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -424,9 +424,9 @@ func TestCatalog_Registration(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_EnableTagOverride(t *testing.T) {
|
||||
|
@ -450,7 +450,7 @@ func TestCatalog_EnableTagOverride(t *testing.T) {
|
|||
Service: service,
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -480,12 +480,12 @@ func TestCatalog_EnableTagOverride(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
service.EnableTagOverride = true
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ func TestCatalog_EnableTagOverride(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestCoordinate_Datacenters(t *testing.T) {
|
|||
|
||||
coordinate := c.Coordinate()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
datacenters, err := coordinate.Datacenters()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -25,9 +25,9 @@ func TestCoordinate_Datacenters(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoordinate_Nodes(t *testing.T) {
|
||||
|
@ -37,7 +37,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||
|
||||
coordinate := c.Coordinate()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, _, err := coordinate.Nodes(nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -48,7 +48,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||
// we can do is call the endpoint and make sure we don't
|
||||
// get an error.
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,15 +29,15 @@ func TestEvent_FireList(t *testing.T) {
|
|||
|
||||
var events []*UserEvent
|
||||
var qm *QueryMeta
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
events, qm, err = event.List("", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return len(events) > 0, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %#v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if events[len(events)-1].ID != id {
|
||||
t.Fatalf("bad: %#v", events)
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestHealth_Node(t *testing.T) {
|
|||
}
|
||||
name := info["Config"]["NodeName"].(string)
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
checks, meta, err := health.Node(name, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -33,9 +33,9 @@ func TestHealth_Node(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", checks)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthChecks_AggregatedStatus(t *testing.T) {
|
||||
|
@ -191,7 +191,7 @@ func TestHealth_Checks(t *testing.T) {
|
|||
}
|
||||
defer agent.ServiceDeregister("foo")
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
checks, meta, err := health.Checks("foo", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -203,9 +203,9 @@ func TestHealth_Checks(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth_Checks_NodeMetaFilter(t *testing.T) {
|
||||
|
@ -231,7 +231,7 @@ func TestHealth_Checks_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
defer agent.ServiceDeregister("foo")
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
checks, meta, err := health.Checks("foo", &QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -243,9 +243,9 @@ func TestHealth_Checks_NodeMetaFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth_Service(t *testing.T) {
|
||||
|
@ -254,7 +254,7 @@ func TestHealth_Service(t *testing.T) {
|
|||
|
||||
health := c.Health()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// consul service should always exist...
|
||||
checks, meta, err := health.Service("consul", "", true, nil)
|
||||
if err != nil {
|
||||
|
@ -270,9 +270,9 @@ func TestHealth_Service(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks[0].Node)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth_Service_NodeMetaFilter(t *testing.T) {
|
||||
|
@ -284,7 +284,7 @@ func TestHealth_Service_NodeMetaFilter(t *testing.T) {
|
|||
|
||||
health := c.Health()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// consul service should always exist...
|
||||
checks, meta, err := health.Service("consul", "", true, &QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
|
@ -300,9 +300,9 @@ func TestHealth_Service_NodeMetaFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks[0].Node)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth_State(t *testing.T) {
|
||||
|
@ -312,7 +312,7 @@ func TestHealth_State(t *testing.T) {
|
|||
|
||||
health := c.Health()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
checks, meta, err := health.State("any", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -324,9 +324,9 @@ func TestHealth_State(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth_State_NodeMetaFilter(t *testing.T) {
|
||||
|
@ -339,7 +339,7 @@ func TestHealth_State_NodeMetaFilter(t *testing.T) {
|
|||
|
||||
health := c.Health()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
checks, meta, err := health.State("any", &QueryOptions{NodeMeta: meta})
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -351,7 +351,7 @@ func TestHealth_State_NodeMetaFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("Bad: %v", checks)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
defer s.Stop()
|
||||
|
||||
operator := c.Operator()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
out, err := operator.AutopilotServerHealth(nil)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
|
@ -200,7 +200,7 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestPreparedQuery(t *testing.T) {
|
|||
}
|
||||
|
||||
catalog := c.Catalog()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if _, err := catalog.Register(reg, nil); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ func TestPreparedQuery(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create a simple prepared query.
|
||||
def := &PreparedQueryDefinition{
|
||||
|
|
|
@ -649,8 +649,6 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (
|
|||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type httpLogHandler struct {
|
||||
|
|
|
@ -346,11 +346,11 @@ func TestAgent_Reload(t *testing.T) {
|
|||
close(doneCh)
|
||||
}()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(cmd.httpServers) == 1, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("should have an http server")
|
||||
})
|
||||
}
|
||||
|
||||
if _, ok := cmd.agent.state.services["redis"]; !ok {
|
||||
t.Fatalf("missing redis service")
|
||||
|
@ -535,11 +535,11 @@ func TestAgent_Join(t *testing.T) {
|
|||
t.Fatalf("should have 2 members")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(a2.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 members")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 members")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_Join_WAN(t *testing.T) {
|
||||
|
@ -570,11 +570,11 @@ func TestAgent_Join_WAN(t *testing.T) {
|
|||
t.Fatalf("should have 2 members")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(a2.WANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 members")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 members")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_Join_ACLDeny(t *testing.T) {
|
||||
|
@ -663,13 +663,13 @@ func TestAgent_Leave(t *testing.T) {
|
|||
t.Fatalf("Err: %v", obj)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
m := srv.agent.LANMembers()
|
||||
success := m[1].Status == serf.StatusLeft
|
||||
return success, errors.New(m[1].Status.String())
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("member status is %v, should be left", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_Leave_ACLDeny(t *testing.T) {
|
||||
|
@ -762,13 +762,13 @@ func TestAgent_ForceLeave(t *testing.T) {
|
|||
t.Fatalf("Err: %v", obj)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
m := srv.agent.LANMembers()
|
||||
success := m[1].Status == serf.StatusLeft
|
||||
return success, errors.New(m[1].Status.String())
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("member status is %v, should be left", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
|
||||
|
@ -1931,7 +1931,7 @@ func TestAgent_Monitor(t *testing.T) {
|
|||
|
||||
// Try to stream logs until we see the expected log line
|
||||
expected := []byte("raft: Initial configuration (index=1)")
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, _ = http.NewRequest("GET", "/v1/agent/monitor?loglevel=debug", nil)
|
||||
resp = newClosableRecorder()
|
||||
done := make(chan struct{})
|
||||
|
@ -1950,9 +1950,9 @@ func TestAgent_Monitor(t *testing.T) {
|
|||
} else {
|
||||
return false, fmt.Errorf("didn't see expected")
|
||||
}
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type closableRecorder struct {
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestCatalogDatacenters(t *testing.T) {
|
|||
defer srv.Shutdown()
|
||||
defer srv.agent.Shutdown()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
obj, err := srv.CatalogDatacenters(nil, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -100,9 +100,9 @@ func TestCatalogDatacenters(t *testing.T) {
|
|||
return false, fmt.Errorf("missing dc: %v", dcs)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogNodes(t *testing.T) {
|
||||
|
@ -219,13 +219,11 @@ func TestCatalogNodes_WanTranslation(t *testing.T) {
|
|||
if _, err := srv2.agent.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Register a node with DC2.
|
||||
{
|
||||
|
@ -701,13 +699,11 @@ func TestCatalogServiceNodes_WanTranslation(t *testing.T) {
|
|||
if _, err := srv2.agent.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Register a node with DC2.
|
||||
{
|
||||
|
@ -942,13 +938,11 @@ func TestCatalogNodeServices_WanTranslation(t *testing.T) {
|
|||
if _, err := srv2.agent.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Register a node with DC2.
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ func expectStatus(t *testing.T, script, status string) {
|
|||
check.Start()
|
||||
defer check.Stop()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// Should have at least 2 updates
|
||||
if mock.Updates("foo") < 2 {
|
||||
return false, fmt.Errorf("should have 2 updates %v", mock.updates)
|
||||
|
@ -90,9 +90,9 @@ func expectStatus(t *testing.T, script, status string) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckMonitor_Passing(t *testing.T) {
|
||||
|
@ -282,7 +282,7 @@ func expectHTTPStatus(t *testing.T, url string, status string) {
|
|||
check.Start()
|
||||
defer check.Stop()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// Should have at least 2 updates
|
||||
if mock.Updates("foo") < 2 {
|
||||
return false, fmt.Errorf("should have 2 updates %v", mock.updates)
|
||||
|
@ -297,9 +297,9 @@ func expectHTTPStatus(t *testing.T, url string, status string) {
|
|||
return false, fmt.Errorf("output too long: %d (%d-byte limit)", n, CheckBufSize)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHTTPCritical(t *testing.T) {
|
||||
|
@ -388,7 +388,7 @@ func TestCheckHTTPTimeout(t *testing.T) {
|
|||
check.Start()
|
||||
defer check.Stop()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// Should have at least 2 updates
|
||||
if mock.updates["bar"] < 2 {
|
||||
return false, fmt.Errorf("should have at least 2 updates %v", mock.updates)
|
||||
|
@ -398,9 +398,9 @@ func TestCheckHTTPTimeout(t *testing.T) {
|
|||
return false, fmt.Errorf("should be critical %v", mock.state)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHTTP_disablesKeepAlives(t *testing.T) {
|
||||
|
@ -461,14 +461,14 @@ func TestCheckHTTP_TLSSkipVerify_true_pass(t *testing.T) {
|
|||
t.Fatalf("should be true")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if mock.state["skipverify_true"] != structs.HealthPassing {
|
||||
return false, fmt.Errorf("should be passing %v", mock.state)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHTTP_TLSSkipVerify_true_fail(t *testing.T) {
|
||||
|
@ -496,14 +496,14 @@ func TestCheckHTTP_TLSSkipVerify_true_fail(t *testing.T) {
|
|||
t.Fatalf("should be true")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if mock.state["skipverify_true"] != structs.HealthCritical {
|
||||
return false, fmt.Errorf("should be critical %v", mock.state)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHTTP_TLSSkipVerify_false(t *testing.T) {
|
||||
|
@ -532,7 +532,7 @@ func TestCheckHTTP_TLSSkipVerify_false(t *testing.T) {
|
|||
t.Fatalf("should be false")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// This should fail due to an invalid SSL cert
|
||||
if mock.state["skipverify_false"] != structs.HealthCritical {
|
||||
return false, fmt.Errorf("should be critical %v", mock.state)
|
||||
|
@ -542,9 +542,9 @@ func TestCheckHTTP_TLSSkipVerify_false(t *testing.T) {
|
|||
return false, fmt.Errorf("should fail with certificate error %v", mock.output)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func mockTCPServer(network string) net.Listener {
|
||||
|
@ -582,7 +582,7 @@ func expectTCPStatus(t *testing.T, tcp string, status string) {
|
|||
check.Start()
|
||||
defer check.Stop()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// Should have at least 2 updates
|
||||
if mock.Updates("foo") < 2 {
|
||||
return false, fmt.Errorf("should have 2 updates %v", mock.updates)
|
||||
|
@ -592,9 +592,9 @@ func expectTCPStatus(t *testing.T, tcp string, status string) {
|
|||
return false, fmt.Errorf("should be %v %v", status, mock.state)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckTCPCritical(t *testing.T) {
|
||||
|
|
|
@ -104,7 +104,7 @@ func TestRetryJoin(t *testing.T) {
|
|||
close(doneCh)
|
||||
}()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
mem := agent.LANMembers()
|
||||
if len(mem) != 2 {
|
||||
return false, fmt.Errorf("bad: %#v", mem)
|
||||
|
@ -114,9 +114,9 @@ func TestRetryJoin(t *testing.T) {
|
|||
return false, fmt.Errorf("bad (wan): %#v", mem)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf(err.Error())
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCliConfig(t *testing.T) {
|
||||
|
|
|
@ -1299,13 +1299,11 @@ func TestDNS_ServiceLookup_WanAddress(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Register a remote node with a service.
|
||||
{
|
||||
|
@ -3376,13 +3374,11 @@ func TestDNS_PreparedQuery_Failover(t *testing.T) {
|
|||
if _, err := srv2.agent.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Register a remote node with a service.
|
||||
{
|
||||
|
|
|
@ -123,7 +123,7 @@ func TestEventList(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -146,9 +146,9 @@ func TestEventList(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", header)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func TestEventList_Filter(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, err := http.NewRequest("GET", "/v1/event/list?name=foo", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -187,9 +187,9 @@ func TestEventList_Filter(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", header)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ func TestEventList_ACLFilter(t *testing.T) {
|
|||
|
||||
// Try no token.
|
||||
{
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -226,14 +226,14 @@ func TestEventList_ACLFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", list)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Try the root token.
|
||||
{
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, err := http.NewRequest("GET", "/v1/event/list?token=root", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -252,9 +252,9 @@ func TestEventList_ACLFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", list)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ func TestEventList_Blocking(t *testing.T) {
|
|||
}
|
||||
|
||||
var index string
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
req, err := http.NewRequest("GET", "/v1/event/list", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -282,9 +282,9 @@ func TestEventList_Blocking(t *testing.T) {
|
|||
}
|
||||
index = header
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
@ -294,7 +294,7 @@ func TestEventList_Blocking(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
url := "/v1/event/list?index=" + index
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
|
@ -314,9 +314,9 @@ func TestEventList_Blocking(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", list)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ func TestEventList_EventBufOrder(t *testing.T) {
|
|||
|
||||
// Test that the event order is preserved when name
|
||||
// filtering on a list of > 1 matching event.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
url := "/v1/event/list?name=foo"
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
|
@ -358,9 +358,9 @@ func TestEventList_EventBufOrder(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %#v", list)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestHealthChecksInState(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := srv.HealthChecksInState(resp, req)
|
||||
if err != nil {
|
||||
|
@ -36,7 +36,9 @@ func TestHealthChecksInState(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", obj)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) { t.Fatalf("err: %v", err) })
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
httpTest(t, func(srv *HTTPServer) {
|
||||
|
@ -45,7 +47,7 @@ func TestHealthChecksInState(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := srv.HealthChecksInState(resp, req)
|
||||
if err != nil {
|
||||
|
@ -61,7 +63,9 @@ func TestHealthChecksInState(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", obj)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) { t.Fatalf("err: %v", err) })
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -88,7 +92,7 @@ func TestHealthChecksInState_NodeMetaFilter(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := srv.HealthChecksInState(resp, req)
|
||||
if err != nil {
|
||||
|
@ -104,7 +108,9 @@ func TestHealthChecksInState_NodeMetaFilter(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", obj)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) { t.Fatalf("err: %v", err) })
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -170,7 +176,7 @@ func TestHealthChecksInState_DistanceSort(t *testing.T) {
|
|||
}
|
||||
|
||||
// Retry until foo moves to the front of the line.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = srv.HealthChecksInState(resp, req)
|
||||
if err != nil {
|
||||
|
@ -188,9 +194,9 @@ func TestHealthChecksInState_DistanceSort(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", nodes)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to get sorted service nodes: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthNodeChecks(t *testing.T) {
|
||||
|
@ -431,7 +437,7 @@ func TestHealthServiceChecks_DistanceSort(t *testing.T) {
|
|||
}
|
||||
|
||||
// Retry until foo has moved to the front of the line.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = srv.HealthServiceChecks(resp, req)
|
||||
if err != nil {
|
||||
|
@ -449,9 +455,9 @@ func TestHealthServiceChecks_DistanceSort(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", nodes)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to get sorted service checks: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthServiceNodes(t *testing.T) {
|
||||
|
@ -665,7 +671,7 @@ func TestHealthServiceNodes_DistanceSort(t *testing.T) {
|
|||
}
|
||||
|
||||
// Retry until foo has moved to the front of the line.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = srv.HealthServiceNodes(resp, req)
|
||||
if err != nil {
|
||||
|
@ -683,9 +689,9 @@ func TestHealthServiceNodes_DistanceSort(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", nodes)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to get sorted service nodes: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
||||
|
@ -761,13 +767,11 @@ func TestHealthServiceNodes_WanTranslation(t *testing.T) {
|
|||
if _, err := srv2.agent.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(srv1.agent.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Register a node with DC2.
|
||||
{
|
||||
|
|
|
@ -183,9 +183,9 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
testutil.WaitForResult(verifyServices, func(err error) {
|
||||
if err := testutil.WaitForResult(verifyServices); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
// Remove one of the services
|
||||
agent.state.RemoveService("api")
|
||||
|
@ -246,9 +246,9 @@ func TestAgentAntiEntropy_Services(t *testing.T) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
testutil.WaitForResult(verifyServicesAfterRemove, func(err error) {
|
||||
if err := testutil.WaitForResult(verifyServicesAfterRemove); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
|
||||
|
@ -350,9 +350,9 @@ func TestAgentAntiEntropy_EnableTagOverride(t *testing.T) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
testutil.WaitForResult(verifyServices, func(err error) {
|
||||
if err := testutil.WaitForResult(verifyServices); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentAntiEntropy_Services_WithChecks(t *testing.T) {
|
||||
|
@ -667,7 +667,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) {
|
|||
var checks structs.IndexedHealthChecks
|
||||
|
||||
// Verify that we are in sync
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Health.NodeChecks", &req, &checks); err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
}
|
||||
|
@ -704,9 +704,9 @@ func TestAgentAntiEntropy_Checks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check the local state
|
||||
if len(agent.state.checks) != 4 {
|
||||
|
@ -749,7 +749,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) {
|
|||
agent.StartSync()
|
||||
|
||||
// Verify that we are in sync
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Health.NodeChecks", &req, &checks); err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
}
|
||||
|
@ -782,9 +782,9 @@ func TestAgentAntiEntropy_Checks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check the local state
|
||||
if len(agent.state.checks) != 3 {
|
||||
|
@ -829,7 +829,7 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
var checks structs.IndexedHealthChecks
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Health.NodeChecks", &req, &checks); err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
}
|
||||
|
@ -840,9 +840,9 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
// Update the check output! Should be deferred
|
||||
agent.state.UpdateCheck("web", structs.HealthPassing, "output")
|
||||
|
@ -864,7 +864,7 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for a deferred update
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Health.NodeChecks", &req, &checks); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -880,9 +880,9 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Change the output in the catalog to force it out of sync.
|
||||
eCopy := check.Clone()
|
||||
|
@ -970,7 +970,7 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for the deferred update.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Health.NodeChecks", &req, &checks); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -986,9 +986,9 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
||||
|
@ -1022,7 +1022,7 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||
var services structs.IndexedNodeServices
|
||||
|
||||
// Wait for the sync
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
}
|
||||
|
@ -1038,9 +1038,9 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", services.NodeServices.Node)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Blow away the catalog version of the node info
|
||||
if err := agent.RPC("Catalog.Register", args, &out); err != nil {
|
||||
|
@ -1052,7 +1052,7 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||
|
||||
// Wait for the sync - this should have been a sync of just the
|
||||
// node info
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
||||
return false, fmt.Errorf("err: %v", err)
|
||||
}
|
||||
|
@ -1066,9 +1066,9 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", services.NodeServices.Node)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentAntiEntropy_deleteService_fails(t *testing.T) {
|
||||
|
@ -1247,7 +1247,7 @@ func TestAgent_sendCoordinate(t *testing.T) {
|
|||
Datacenter: agent.config.Datacenter,
|
||||
}
|
||||
var reply structs.IndexedCoordinates
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if err := agent.RPC("Coordinate.ListNodes", &req, &reply); err != nil {
|
||||
return false, fmt.Errorf("err: %s", err)
|
||||
}
|
||||
|
@ -1259,7 +1259,7 @@ func TestAgent_sendCoordinate(t *testing.T) {
|
|||
return false, fmt.Errorf("bad: %v", coord)
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -435,7 +435,7 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := srv.OperatorServerHealth(resp, req)
|
||||
if err != nil {
|
||||
|
@ -457,9 +457,9 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
}, cb)
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ func TestOperator_ServerHealth_Unhealthy(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
resp := httptest.NewRecorder()
|
||||
obj, err := srv.OperatorServerHealth(resp, req)
|
||||
if err != nil {
|
||||
|
@ -497,9 +497,9 @@ func TestOperator_ServerHealth_Unhealthy(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
}, cb)
|
||||
}
|
||||
|
|
|
@ -175,13 +175,11 @@ func TestFireReceiveEvent(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(agent.UserEvents()) == 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(agent.UserEvents()) == 1, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
last := agent.LastUserEvent()
|
||||
if last.ID != p2.ID {
|
||||
|
|
|
@ -86,12 +86,12 @@ func waitForLeader(t *testing.T, httpAddr string) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, qm, err := client.Catalog().Nodes(nil)
|
||||
return err == nil && qm.KnownLeader && qm.LastIndex > 0, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to find leader: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func httpClient(addr string) (*consulapi.Client, error) {
|
||||
|
@ -194,15 +194,15 @@ func TestExecCommand_Sessions_Foreign(t *testing.T) {
|
|||
c.conf.localNode = "foo"
|
||||
|
||||
var id string
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
id, err = c.createSession()
|
||||
if err != nil && strings.Contains(err.Error(), "Failed to find Consul server") {
|
||||
err = nil
|
||||
}
|
||||
return id != "", err
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
se, _, err := client.Session().Info(id, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -3,12 +3,13 @@ package command
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/consul/command/base"
|
||||
"github.com/hashicorp/consul/testutil"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
"github.com/mitchellh/cli"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testForceLeaveCommand(t *testing.T) (*cli.MockUi, *ForceLeaveCommand) {
|
||||
|
@ -56,13 +57,13 @@ func TestForceLeaveCommandRun(t *testing.T) {
|
|||
t.Fatalf("should have 2 members: %#v", m)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
m = a1.agent.LANMembers()
|
||||
success := m[1].Status == serf.StatusLeft
|
||||
return success, errors.New(m[1].Status.String())
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("member status is %v, should be left", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestForceLeaveCommandRun_noAddrs(t *testing.T) {
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestRTTCommand_Run_LAN(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for the updates to get flushed to the data store.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
code := c.Run(args)
|
||||
if code != 0 {
|
||||
return false, fmt.Errorf("bad: %d: %#v", code, ui.ErrorWriter.String())
|
||||
|
@ -121,9 +121,9 @@ func TestRTTCommand_Run_LAN(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("failed to get proper RTT output: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Default to the agent's node.
|
||||
{
|
||||
|
|
|
@ -395,9 +395,9 @@ func TestACLReplication(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for the replica to converge.
|
||||
testutil.WaitForResult(checkSame, func(err error) {
|
||||
if err := testutil.WaitForResult(checkSame); err != nil {
|
||||
t.Fatalf("ACLs didn't converge")
|
||||
})
|
||||
}
|
||||
|
||||
// Create more new tokens.
|
||||
for i := 0; i < 1000; i++ {
|
||||
|
@ -418,9 +418,9 @@ func TestACLReplication(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for the replica to converge.
|
||||
testutil.WaitForResult(checkSame, func(err error) {
|
||||
if err := testutil.WaitForResult(checkSame); err != nil {
|
||||
t.Fatalf("ACLs didn't converge")
|
||||
})
|
||||
}
|
||||
|
||||
// Delete a token.
|
||||
arg := structs.ACLRequest{
|
||||
|
@ -437,7 +437,7 @@ func TestACLReplication(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for the replica to converge.
|
||||
testutil.WaitForResult(checkSame, func(err error) {
|
||||
if err := testutil.WaitForResult(checkSame); err != nil {
|
||||
t.Fatalf("ACLs didn't converge")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,12 +232,12 @@ func TestACL_NonAuthority_NotFound(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client := rpcClient(t, s1)
|
||||
defer client.Close()
|
||||
|
@ -284,12 +284,12 @@ func TestACL_NonAuthority_Found(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Create a new token
|
||||
|
@ -360,12 +360,12 @@ func TestACL_NonAuthority_Management(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// find the non-authoritative server
|
||||
|
@ -417,12 +417,12 @@ func TestACL_DownPolicy_Deny(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Create a new token
|
||||
|
@ -491,12 +491,12 @@ func TestACL_DownPolicy_Allow(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Create a new token
|
||||
|
@ -567,12 +567,12 @@ func TestACL_DownPolicy_ExtendCache(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ := s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Create a new token
|
||||
|
@ -687,7 +687,7 @@ func TestACL_Replication(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for replication to occur.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, acl, err := s2.fsm.State().ACLGet(nil, id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -703,9 +703,9 @@ func TestACL_Replication(t *testing.T) {
|
|||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("ACLs didn't converge")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Kill the ACL datacenter.
|
||||
s1.Shutdown()
|
||||
|
|
|
@ -49,12 +49,12 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Bring up a new server
|
||||
|
@ -65,7 +65,7 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
// Kill a non-leader server
|
||||
s3.Shutdown()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
alive := 0
|
||||
for _, m := range s1.LANMembers() {
|
||||
if m.Status == serf.StatusAlive {
|
||||
|
@ -73,9 +73,9 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
}
|
||||
}
|
||||
return alive == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 alive members")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Join the new server
|
||||
if _, err := s4.JoinLAN([]string{addr}); err != nil {
|
||||
|
@ -85,12 +85,12 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
|
||||
// Make sure the dead server is removed and we're back to 3 total peers
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,12 +131,12 @@ func TestAutopilot_CleanupDeadServerPeriodic(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 4, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 4 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Kill a non-leader server
|
||||
|
@ -144,12 +144,12 @@ func TestAutopilot_CleanupDeadServerPeriodic(t *testing.T) {
|
|||
|
||||
// Should be removed from the peers automatically
|
||||
for _, s := range []*Server{s1, s2, s3} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||
// Wait for the new server to be added as a non-voter, but make sure
|
||||
// it doesn't get promoted to a voter even after ServerStabilizationTime,
|
||||
// because that would result in an even-numbered quorum count.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
future := s1.raft.GetConfiguration()
|
||||
if err := future.Error(); err != nil {
|
||||
return false, err
|
||||
|
@ -211,9 +211,9 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
|
||||
// Now add another server and make sure they both get promoted to voters after stabilization
|
||||
dir3, s3 := testServerWithConfig(t, func(c *Config) {
|
||||
|
@ -227,7 +227,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
future := s1.raft.GetConfiguration()
|
||||
if err := future.Error(); err != nil {
|
||||
return false, err
|
||||
|
@ -246,7 +246,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -601,12 +601,12 @@ func TestCatalog_ListNodes(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||
return len(out.Nodes) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Server node is auto added from Serf
|
||||
if out.Nodes[1].Node != s1.config.NodeName {
|
||||
|
@ -644,12 +644,12 @@ func TestCatalog_ListNodes_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
var out structs.IndexedNodes
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||
return len(out.Nodes) == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Verify that only the correct node was returned
|
||||
if out.Nodes[0].Node != "foo" {
|
||||
|
@ -676,12 +676,12 @@ func TestCatalog_ListNodes_NodeMetaFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should get an empty list of nodes back
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||
return len(out.Nodes) == 0, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalog_ListNodes_StaleRaad(t *testing.T) {
|
||||
|
@ -887,12 +887,12 @@ func TestCatalog_ListNodes_DistanceSort(t *testing.T) {
|
|||
Datacenter: "dc1",
|
||||
}
|
||||
var out structs.IndexedNodes
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||
return len(out.Nodes) == 5, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.Nodes[0].Node != "aaa" {
|
||||
t.Fatalf("bad: %v", out)
|
||||
}
|
||||
|
@ -915,12 +915,12 @@ func TestCatalog_ListNodes_DistanceSort(t *testing.T) {
|
|||
Datacenter: "dc1",
|
||||
Source: structs.QuerySource{Datacenter: "dc1", Node: "foo"},
|
||||
}
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||
return len(out.Nodes) == 5, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.Nodes[0].Node != "foo" {
|
||||
t.Fatalf("bad: %v", out)
|
||||
}
|
||||
|
|
|
@ -84,27 +84,27 @@ func TestClient_JoinLAN(t *testing.T) {
|
|||
if _, err := c1.JoinLAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return c1.servers.NumServers() == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("expected consul server")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("expected consul server")
|
||||
}
|
||||
|
||||
// Check the members
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
server_check := len(s1.LANMembers()) == 2
|
||||
client_check := len(c1.LANMembers()) == 2
|
||||
return server_check && client_check, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check we have a new consul
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return c1.servers.NumServers() == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("expected consul server")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("expected consul server")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_JoinLAN_Invalid(t *testing.T) {
|
||||
|
@ -189,12 +189,12 @@ func TestClient_RPC(t *testing.T) {
|
|||
}
|
||||
|
||||
// RPC should succeed
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
err := c1.RPC("Status.Ping", struct{}{}, &out)
|
||||
return err == nil, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_RPC_Pool(t *testing.T) {
|
||||
|
@ -214,12 +214,12 @@ func TestClient_RPC_Pool(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for both agents to finish joining
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.LANMembers()) == 2 && len(c1.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("Server has %v of %v expected members; Client has %v of %v expected members.",
|
||||
len(s1.LANMembers()), 2, len(c1.LANMembers()), 2)
|
||||
})
|
||||
}
|
||||
|
||||
// Blast out a bunch of RPC requests at the same time to try to get
|
||||
// contention opening new connections.
|
||||
|
@ -230,12 +230,12 @@ func TestClient_RPC_Pool(t *testing.T) {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
var out struct{}
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
err := c1.RPC("Status.Ping", struct{}{}, &out)
|
||||
return err == nil, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ func TestClient_RPC_TLS(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait for joins to finish/RPC to succeed
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
if len(s1.LANMembers()) != 2 {
|
||||
return false, fmt.Errorf("bad len: %v", len(s1.LANMembers()))
|
||||
}
|
||||
|
@ -356,9 +356,9 @@ func TestClient_RPC_TLS(t *testing.T) {
|
|||
|
||||
err := c1.RPC("Status.Ping", struct{}{}, &out)
|
||||
return err == nil, err
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_SnapshotRPC(t *testing.T) {
|
||||
|
@ -384,11 +384,11 @@ func TestClient_SnapshotRPC(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait until we've got a healthy server.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return c1.servers.NumServers() == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("expected consul server")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("expected consul server")
|
||||
}
|
||||
|
||||
// Take a snapshot.
|
||||
var snap bytes.Buffer
|
||||
|
@ -443,11 +443,11 @@ func TestClient_SnapshotRPC_TLS(t *testing.T) {
|
|||
}
|
||||
|
||||
// Wait until we've got a healthy server.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return c1.servers.NumServers() == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("expected consul server")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("expected consul server")
|
||||
}
|
||||
|
||||
// Take a snapshot.
|
||||
var snap bytes.Buffer
|
||||
|
@ -496,11 +496,11 @@ func TestClientServer_UserEvent(t *testing.T) {
|
|||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
// Check the members
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(c1.LANMembers()) == 2 && len(s1.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Fire the user event
|
||||
codec := rpcClient(t, s1)
|
||||
|
|
|
@ -351,7 +351,7 @@ func TestCoordinate_ListNodes(t *testing.T) {
|
|||
}
|
||||
|
||||
// Now query back for all the nodes.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
arg := structs.DCSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
|
@ -369,7 +369,9 @@ func TestCoordinate_ListNodes(t *testing.T) {
|
|||
verifyCoordinatesEqual(t, resp.Coordinates[1].Coord, arg3.Coord) // baz
|
||||
verifyCoordinatesEqual(t, resp.Coordinates[2].Coord, arg1.Coord) // foo
|
||||
return true, nil
|
||||
}, func(err error) { t.Fatalf("err: %v", err) })
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoordinate_ListNodes_ACLFilter(t *testing.T) {
|
||||
|
@ -444,7 +446,7 @@ func TestCoordinate_ListNodes_ACLFilter(t *testing.T) {
|
|||
// Wait for all the coordinate updates to apply. Since we aren't
|
||||
// enforcing version 8 ACLs, this should also allow us to read
|
||||
// everything back without a token.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
arg := structs.DCSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
|
@ -456,7 +458,9 @@ func TestCoordinate_ListNodes_ACLFilter(t *testing.T) {
|
|||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("bad: %v", resp.Coordinates)
|
||||
}, func(err error) { t.Fatalf("err: %v", err) })
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Now that we've waited for the batch processing to ingest the
|
||||
// coordinates we can do the rest of the requests without the loop. We
|
||||
|
|
|
@ -33,15 +33,15 @@ func TestLeader_RegisterMember(t *testing.T) {
|
|||
|
||||
// Client should be registered
|
||||
state := s1.fsm.State()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node != nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client not registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client not registered")
|
||||
}
|
||||
|
||||
// Should have a check
|
||||
_, checks, err := state.NodeChecks(nil, c1.config.NodeName)
|
||||
|
@ -103,15 +103,15 @@ func TestLeader_FailedMember(t *testing.T) {
|
|||
|
||||
// Should be registered
|
||||
state := s1.fsm.State()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node != nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client not registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client not registered")
|
||||
}
|
||||
|
||||
// Should have a check
|
||||
_, checks, err := state.NodeChecks(nil, c1.config.NodeName)
|
||||
|
@ -128,15 +128,15 @@ func TestLeader_FailedMember(t *testing.T) {
|
|||
t.Fatalf("bad check: %v", checks[0])
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, checks, err = state.NodeChecks(nil, c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return checks[0].Status == structs.HealthCritical, errors.New(checks[0].Status)
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("check status is %v, should be critical", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_LeftMember(t *testing.T) {
|
||||
|
@ -158,30 +158,30 @@ func TestLeader_LeftMember(t *testing.T) {
|
|||
state := s1.fsm.State()
|
||||
|
||||
// Should be registered
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node != nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client should be registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client should be registered")
|
||||
}
|
||||
|
||||
// Node should leave
|
||||
c1.Leave()
|
||||
c1.Shutdown()
|
||||
|
||||
// Should be deregistered
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node == nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client should not be registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client should not be registered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_ReapMember(t *testing.T) {
|
||||
|
@ -203,15 +203,15 @@ func TestLeader_ReapMember(t *testing.T) {
|
|||
state := s1.fsm.State()
|
||||
|
||||
// Should be registered
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node != nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client should be registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client should be registered")
|
||||
}
|
||||
|
||||
// Simulate a node reaping
|
||||
mems := s1.LANMembers()
|
||||
|
@ -310,15 +310,15 @@ func TestLeader_Reconcile(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should be registered
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err = state.GetNode(c1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node != nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("client should be registered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("client should be registered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_LeftServer(t *testing.T) {
|
||||
|
@ -346,15 +346,15 @@ func TestLeader_LeftServer(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
// Kill any server
|
||||
servers[0].Shutdown()
|
||||
|
||||
|
@ -369,9 +369,9 @@ func TestLeader_LeftServer(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_LeftLeader(t *testing.T) {
|
||||
|
@ -399,12 +399,12 @@ func TestLeader_LeftLeader(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
// Kill the leader!
|
||||
|
@ -428,25 +428,25 @@ func TestLeader_LeftLeader(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
remain = s
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 2, errors.New(fmt.Sprintf("%d", peers))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 peers")
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the old leader is deregistered
|
||||
state := remain.fsm.State()
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
_, node, err := state.GetNode(leader.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
return node == nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("leader should be deregistered")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should be deregistered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_MultiBootstrap(t *testing.T) {
|
||||
|
@ -468,12 +468,12 @@ func TestLeader_MultiBootstrap(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers := s.serfLAN.Members()
|
||||
return len(peers) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 peerss")
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we don't have multiple raft peers
|
||||
|
@ -510,12 +510,12 @@ func TestLeader_TombstoneGC_Reset(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
var leader *Server
|
||||
|
@ -540,7 +540,7 @@ func TestLeader_TombstoneGC_Reset(t *testing.T) {
|
|||
|
||||
// Wait for a new leader
|
||||
leader = nil
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
for _, s := range servers {
|
||||
if s.IsLeader() {
|
||||
leader = s
|
||||
|
@ -548,16 +548,16 @@ func TestLeader_TombstoneGC_Reset(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return false, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have leader")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have leader")
|
||||
}
|
||||
|
||||
// Check that the new leader has a pending GC expiration
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return leader.tombstoneGC.PendingExpiration(), nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have pending expiration")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have pending expiration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_ReapTombstones(t *testing.T) {
|
||||
|
@ -610,7 +610,7 @@ func TestLeader_ReapTombstones(t *testing.T) {
|
|||
|
||||
// Check that the new leader has a pending GC expiration by
|
||||
// watching for the tombstone to get removed.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
snap := state.Snapshot()
|
||||
defer snap.Close()
|
||||
stones, err := snap.Tombstones()
|
||||
|
@ -618,9 +618,9 @@ func TestLeader_ReapTombstones(t *testing.T) {
|
|||
return false, err
|
||||
}
|
||||
return stones.Next() == nil, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeader_RollRaftServer(t *testing.T) {
|
||||
|
@ -656,24 +656,24 @@ func TestLeader_RollRaftServer(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
// Kill the v1 server
|
||||
s2.Shutdown()
|
||||
|
||||
for _, s := range []*Server{s1, s3} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
minVer, err := ServerMinRaftProtocol(s.LANMembers())
|
||||
return minVer == 2, err
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("minimum protocol version among servers should be 2")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the dead server with one running raft protocol v3
|
||||
|
@ -691,7 +691,7 @@ func TestLeader_RollRaftServer(t *testing.T) {
|
|||
|
||||
// Make sure the dead server is removed and we're back to 3 total peers
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
addrs := 0
|
||||
ids := 0
|
||||
future := s.raft.GetConfiguration()
|
||||
|
@ -706,9 +706,9 @@ func TestLeader_RollRaftServer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return addrs == 2 && ids == 1, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("should see 2 legacy IDs and 1 GUID")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -744,18 +744,18 @@ func TestLeader_ChangeServerAddress(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
// Shut down a server, freeing up its address/port
|
||||
s3.Shutdown()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
alive := 0
|
||||
for _, m := range s1.LANMembers() {
|
||||
if m.Status == serf.StatusAlive {
|
||||
|
@ -763,9 +763,9 @@ func TestLeader_ChangeServerAddress(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return alive == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 alive members")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 alive members")
|
||||
}
|
||||
|
||||
// Bring up a new server with s3's address that will get a different ID
|
||||
dir4, s4 := testServerWithConfig(t, func(c *Config) {
|
||||
|
@ -784,12 +784,12 @@ func TestLeader_ChangeServerAddress(t *testing.T) {
|
|||
|
||||
// Make sure the dead server is removed and we're back to 3 total peers
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 members")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -825,18 +825,18 @@ func TestLeader_ChangeServerID(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
|
||||
// Shut down a server, freeing up its address/port
|
||||
s3.Shutdown()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
alive := 0
|
||||
for _, m := range s1.LANMembers() {
|
||||
if m.Status == serf.StatusAlive {
|
||||
|
@ -844,9 +844,9 @@ func TestLeader_ChangeServerID(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return alive == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 alive members")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 2 alive members")
|
||||
}
|
||||
|
||||
// Bring up a new server with s3's address that will get a different ID
|
||||
dir4, s4 := testServerWithConfig(t, func(c *Config) {
|
||||
|
@ -867,11 +867,11 @@ func TestLeader_ChangeServerID(t *testing.T) {
|
|||
|
||||
// Make sure the dead server is removed and we're back to 3 total peers
|
||||
for _, s := range servers {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("should have 3 peers")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
"github.com/hashicorp/consul/testutil"
|
||||
"github.com/hashicorp/net-rpc-msgpackrpc"
|
||||
"github.com/hashicorp/raft"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestOperator_RaftGetConfiguration(t *testing.T) {
|
||||
|
@ -461,7 +462,7 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
|
||||
testutil.WaitForLeader(t, s1.RPC, "dc1")
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
arg := structs.DCSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
|
@ -490,9 +491,9 @@ func TestOperator_ServerHealth(t *testing.T) {
|
|||
}
|
||||
}
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperator_ServerHealth_UnsupportedRaftVersion(t *testing.T) {
|
||||
|
|
|
@ -1453,13 +1453,11 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
|||
if _, err := s2.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Create an ACL with read permission to the service.
|
||||
var execToken string
|
||||
|
@ -2704,13 +2702,11 @@ func TestPreparedQuery_Wrapper(t *testing.T) {
|
|||
if _, err := s2.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
}
|
||||
|
||||
// Try all the operations on a real server via the wrapper.
|
||||
wrapper := &queryServerWrapper{s1}
|
||||
|
|
|
@ -177,17 +177,17 @@ func TestServer_JoinLAN(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the members
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_JoinWAN(t *testing.T) {
|
||||
|
@ -207,28 +207,28 @@ func TestServer_JoinWAN(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the members
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.WANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.WANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check the router has both
|
||||
if len(s1.router.GetDatacenters()) != 2 {
|
||||
t.Fatalf("remote consul missing")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.router.GetDatacenters()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("remote consul missing")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("remote consul missing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_JoinWAN_Flood(t *testing.T) {
|
||||
|
@ -248,11 +248,11 @@ func TestServer_JoinWAN_Flood(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, s := range []*Server{s1, s2} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s.WANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("bad len for server %d", i)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
dir3, s3 := testServer(t)
|
||||
|
@ -268,11 +268,11 @@ func TestServer_JoinWAN_Flood(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, s := range []*Server{s1, s2, s3} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s.WANMembers()) == 3, nil
|
||||
}, func(err error) {
|
||||
}); err != nil {
|
||||
t.Fatalf("bad len for server %d", i)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,32 +312,32 @@ func TestServer_JoinSeparateLanAndWanAddresses(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the WAN members on s1
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.WANMembers()) == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check the WAN members on s2
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.WANMembers()) == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check the LAN members on s2
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check the LAN members on s3
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s3.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Check the router has both
|
||||
if len(s1.router.GetDatacenters()) != 2 {
|
||||
|
@ -395,19 +395,19 @@ func TestServer_LeaveLeader(t *testing.T) {
|
|||
var p1 int
|
||||
var p2 int
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 2 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 2 peers %s", err)
|
||||
}
|
||||
|
||||
// Issue a leave to the leader
|
||||
for _, s := range []*Server{s1, s2} {
|
||||
|
@ -421,12 +421,12 @@ func TestServer_LeaveLeader(t *testing.T) {
|
|||
|
||||
// Should lose a peer
|
||||
for _, s := range []*Server{s1, s2} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s.numPeers()
|
||||
return p1 == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 1 peer: %v", p1)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 1 peer %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,19 +450,19 @@ func TestServer_Leave(t *testing.T) {
|
|||
var p1 int
|
||||
var p2 int
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 2 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 2, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 2 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 2 peers %s", err)
|
||||
}
|
||||
|
||||
// Issue a leave to the non-leader
|
||||
for _, s := range []*Server{s1, s2} {
|
||||
|
@ -476,12 +476,12 @@ func TestServer_Leave(t *testing.T) {
|
|||
|
||||
// Should lose a peer
|
||||
for _, s := range []*Server{s1, s2} {
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s.numPeers()
|
||||
return p1 == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 1 peer: %v", p1)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 1 peer %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,32 +528,32 @@ func TestServer_JoinLAN_TLS(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check the members
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s2.LANMembers()) == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("bad len")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal("bad len")
|
||||
}
|
||||
|
||||
// Verify Raft has established a peer
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s1.numPeers()
|
||||
return peers == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("no peer established")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("no peers")
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s2.numPeers()
|
||||
return peers == 2, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("no peer established")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("no peers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_Expect(t *testing.T) {
|
||||
|
@ -587,19 +587,19 @@ func TestServer_Expect(t *testing.T) {
|
|||
var p2 int
|
||||
|
||||
// Should have no peers yet since the bootstrap didn't occur.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 0, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 0, errors.New(fmt.Sprintf("%d", p2))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
// Join the third node.
|
||||
if _, err := s3.JoinLAN([]string{addr}); err != nil {
|
||||
|
@ -609,26 +609,26 @@ func TestServer_Expect(t *testing.T) {
|
|||
var p3 int
|
||||
|
||||
// Now we have three servers so we should bootstrap.
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 3, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 3 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 3, errors.New(fmt.Sprintf("%d", p2))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 3 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p3, _ = s3.numPeers()
|
||||
return p3 == 3, errors.New(fmt.Sprintf("%d", p3))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 3 peers %s", err)
|
||||
}
|
||||
|
||||
// Make sure a leader is elected, grab the current term and then add in
|
||||
// the fourth server.
|
||||
|
@ -640,12 +640,12 @@ func TestServer_Expect(t *testing.T) {
|
|||
|
||||
// Wait for the new server to see itself added to the cluster.
|
||||
var p4 int
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p4, _ = s4.numPeers()
|
||||
return p4 == 4, errors.New(fmt.Sprintf("%d", p4))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 4 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 4 peers %s", err)
|
||||
}
|
||||
|
||||
// Make sure there's still a leader and that the term didn't change,
|
||||
// so we know an election didn't occur.
|
||||
|
@ -683,19 +683,19 @@ func TestServer_BadExpect(t *testing.T) {
|
|||
var p2 int
|
||||
|
||||
// should have no peers yet
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 0, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 0, errors.New(fmt.Sprintf("%d", p2))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
// join the third node
|
||||
if _, err := s3.JoinLAN([]string{addr}); err != nil {
|
||||
|
@ -705,26 +705,26 @@ func TestServer_BadExpect(t *testing.T) {
|
|||
var p3 int
|
||||
|
||||
// should still have no peers (because s2 is in expect=2 mode)
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p1, _ = s1.numPeers()
|
||||
return p1 == 0, errors.New(fmt.Sprintf("%d", p1))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p2, _ = s2.numPeers()
|
||||
return p2 == 0, errors.New(fmt.Sprintf("%d", p2))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
p3, _ = s3.numPeers()
|
||||
return p3 == 0, errors.New(fmt.Sprintf("%d", p3))
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 0 peers: %v", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 0 peers %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeGlobalResp struct{}
|
||||
|
@ -742,11 +742,11 @@ func TestServer_globalRPCErrors(t *testing.T) {
|
|||
defer os.RemoveAll(dir1)
|
||||
defer s1.Shutdown()
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.router.GetDatacenters()) == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("Server did not join WAN successfully")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("did not join WAN")
|
||||
}
|
||||
|
||||
// Check that an error from a remote DC is returned
|
||||
err := s1.globalRPC("Bad.Method", nil, &fakeGlobalResp{})
|
||||
|
|
|
@ -298,12 +298,12 @@ func TestServer_SessionTTL_Failover(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
peers, _ := s1.numPeers()
|
||||
return peers == 3, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have 3 peers")
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatalf("should have 3 peers %s", err)
|
||||
}
|
||||
|
||||
// Find the leader
|
||||
var leader *Server
|
||||
|
@ -363,7 +363,7 @@ func TestServer_SessionTTL_Failover(t *testing.T) {
|
|||
}
|
||||
|
||||
// Find the new leader
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
leader = nil
|
||||
for _, s := range servers {
|
||||
if s.IsLeader() {
|
||||
|
@ -380,7 +380,7 @@ func TestServer_SessionTTL_Failover(t *testing.T) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("err: %s", err)
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,13 +329,11 @@ func TestSnapshot_Forward_Datacenter(t *testing.T) {
|
|||
if _, err := s2.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
testutil.WaitForResult(
|
||||
func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf("Failed waiting for WAN join: %v", err)
|
||||
})
|
||||
if err := testutil.WaitForResult(func() (bool, error) {
|
||||
return len(s1.WANMembers()) > 1, nil
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to join WAN: %s", err)
|
||||
}
|
||||
|
||||
// Run a snapshot from each server locally and remotely to ensure we
|
||||
// forward.
|
||||
|
|
Loading…
Reference in New Issue