mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Create AssertUntil helper func
This commit is contained in:
@@ -414,14 +414,18 @@ func TestClient_MixedTLS(t *testing.T) {
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
var out structs.SingleNodeResponse
|
||||
deadline := time.Now().Add(100 * time.Millisecond)
|
||||
for time.Now().Before(deadline) {
|
||||
err := c1.RPC("Node.GetNode", &req, &out)
|
||||
if err == nil {
|
||||
t.Fatalf("client RPC succeeded when it should have failed:\n%+v", out)
|
||||
}
|
||||
time.Sleep(3 * time.Millisecond)
|
||||
}
|
||||
testutil.AssertUntil(100*time.Millisecond,
|
||||
func() (bool, error) {
|
||||
err := c1.RPC("Node.GetNode", &req, &out)
|
||||
if err == nil {
|
||||
return false, fmt.Errorf("client RPC succeeded when it should have failed:\n%+v", out)
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf(err.Error())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// TestClient_BadTLS asserts that when a client and server are running with TLS
|
||||
@@ -467,14 +471,18 @@ func TestClient_BadTLS(t *testing.T) {
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
var out structs.SingleNodeResponse
|
||||
deadline := time.Now().Add(100 * time.Millisecond)
|
||||
for time.Now().Before(deadline) {
|
||||
err := c1.RPC("Node.GetNode", &req, &out)
|
||||
if err == nil {
|
||||
t.Fatalf("client RPC succeeded when it should have failed:\n%+v", out)
|
||||
}
|
||||
time.Sleep(3 * time.Millisecond)
|
||||
}
|
||||
testutil.AssertUntil(100*time.Millisecond,
|
||||
func() (bool, error) {
|
||||
err := c1.RPC("Node.GetNode", &req, &out)
|
||||
if err == nil {
|
||||
return false, fmt.Errorf("client RPC succeeded when it should have failed:\n%+v", out)
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
func(err error) {
|
||||
t.Fatalf(err.Error())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestClient_Register(t *testing.T) {
|
||||
|
||||
@@ -37,6 +37,21 @@ func WaitForResultRetries(retries int64, test testFn, error errorFn) {
|
||||
}
|
||||
}
|
||||
|
||||
// AssertUntil asserts the test function passes throughout the given duration.
|
||||
// Otherwise error is called on failure.
|
||||
func AssertUntil(until time.Duration, test testFn, error errorFn) {
|
||||
deadline := time.Now().Add(until)
|
||||
for time.Now().Before(deadline) {
|
||||
success, err := test()
|
||||
if !success {
|
||||
error(err)
|
||||
return
|
||||
}
|
||||
// Sleep some arbitrary fraction of the deadline
|
||||
time.Sleep(until / 30)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMultiplier returns a multiplier for retries and waits given environment
|
||||
// the tests are being run under.
|
||||
func TestMultiplier() int64 {
|
||||
|
||||
Reference in New Issue
Block a user