api: use WaitForResult() to improve health tests
This commit is contained in:
parent
77f041b41f
commit
9beeb6c81b
|
@ -1,8 +1,10 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
"github.com/hashicorp/consul/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHealth_Node(t *testing.T) {
|
func TestHealth_Node(t *testing.T) {
|
||||||
|
@ -50,20 +52,21 @@ func TestHealth_Checks(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer agent.ServiceDeregister("foo")
|
defer agent.ServiceDeregister("foo")
|
||||||
|
|
||||||
// Wait for the register...
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
time.Sleep(20 * time.Millisecond)
|
|
||||||
|
|
||||||
checks, meta, err := health.Checks("foo", nil)
|
checks, meta, err := health.Checks("foo", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.LastIndex == 0 {
|
if meta.LastIndex == 0 {
|
||||||
t.Fatalf("bad: %v", meta)
|
return false, fmt.Errorf("bad: %v", meta)
|
||||||
}
|
}
|
||||||
if len(checks) == 0 {
|
if len(checks) == 0 {
|
||||||
t.Fatalf("Bad: %v", checks)
|
return false, fmt.Errorf("Bad: %v", checks)
|
||||||
}
|
}
|
||||||
|
return true, nil
|
||||||
|
}, func(err error) {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealth_Service(t *testing.T) {
|
func TestHealth_Service(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue