mirror of https://github.com/status-im/consul.git
More flaky test fixes (#6151)
* Add retry to TestAPI_ClientTxn * Add retry to TestLeader_RegisterMember * Account for empty watch result in ConnectRootsWatch
This commit is contained in:
parent
95dbb7f2f1
commit
59dbd070d7
|
@ -68,13 +68,15 @@ func TestLeader_RegisterMember(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server should be registered
|
// Server should be registered
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
_, node, err := state.GetNode(s1.config.NodeName)
|
_, node, err := state.GetNode(s1.config.NodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if node == nil {
|
if node == nil {
|
||||||
t.Fatalf("server not registered")
|
r.Fatalf("server not registered")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Service should be registered
|
// Service should be registered
|
||||||
_, services, err := state.NodeServices(nil, s1.config.NodeName)
|
_, services, err := state.NodeServices(nil, s1.config.NodeName)
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-uuid"
|
"github.com/hashicorp/go-uuid"
|
||||||
|
|
||||||
"github.com/pascaldekloe/goe/verify"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPI_ClientTxn(t *testing.T) {
|
func TestAPI_ClientTxn(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
require := require.New(t)
|
|
||||||
c, s := makeClient(t)
|
c, s := makeClient(t)
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
|
|
||||||
// Set up a test service and health check.
|
// Set up a test service and health check.
|
||||||
nodeID, err := uuid.GenerateUUID()
|
nodeID, err := uuid.GenerateUUID()
|
||||||
require.NoError(err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
catalog := c.Catalog()
|
catalog := c.Catalog()
|
||||||
reg := &CatalogRegistration{
|
reg := &CatalogRegistration{
|
||||||
|
@ -59,11 +58,11 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = catalog.Register(reg, nil)
|
_, err = catalog.Register(reg, nil)
|
||||||
require.NoError(err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
node, _, err := catalog.Node("foo", nil)
|
node, _, err := catalog.Node("foo", nil)
|
||||||
require.NoError(err)
|
require.NoError(t, err)
|
||||||
require.Equal(nodeID, node.Node.ID)
|
require.Equal(t, nodeID, node.Node.ID)
|
||||||
|
|
||||||
// Make a session.
|
// Make a session.
|
||||||
id, _, err := session.CreateNoChecks(nil, nil)
|
id, _, err := session.CreateNoChecks(nil, nil)
|
||||||
|
@ -218,8 +217,9 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
verify.Values(t, "", ret.Results, expected)
|
require.Equal(t, ret.Results, expected)
|
||||||
|
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Run a read-only transaction.
|
// Run a read-only transaction.
|
||||||
ops = TxnOps{
|
ops = TxnOps{
|
||||||
&TxnOp{
|
&TxnOp{
|
||||||
|
@ -237,9 +237,9 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
}
|
}
|
||||||
ok, ret, _, err = txn.Txn(ops, nil)
|
ok, ret, _, err = txn.Txn(ops, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
r.Fatalf("err: %v", err)
|
||||||
} else if !ok {
|
} else if !ok {
|
||||||
t.Fatalf("transaction failure")
|
r.Fatalf("transaction failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = TxnResults{
|
expected = TxnResults{
|
||||||
|
@ -269,7 +269,8 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
verify.Values(t, "", ret.Results, expected)
|
require.Equal(r, ret.Results, expected)
|
||||||
|
})
|
||||||
|
|
||||||
// Sanity check using the regular GET API.
|
// Sanity check using the regular GET API.
|
||||||
kv := c.KV()
|
kv := c.KV()
|
||||||
|
|
|
@ -715,7 +715,7 @@ func TestConnectRootsWatch(t *testing.T) {
|
||||||
return // ignore
|
return // ignore
|
||||||
}
|
}
|
||||||
v, ok := raw.(*api.CARootList)
|
v, ok := raw.(*api.CARootList)
|
||||||
if !ok || v == nil {
|
if !ok || v == nil || len(v.Roots) == 0 {
|
||||||
return // ignore
|
return // ignore
|
||||||
}
|
}
|
||||||
// Only 1 CA is the bootstrapped state (i.e. first response). Ignore this
|
// Only 1 CA is the bootstrapped state (i.e. first response). Ignore this
|
||||||
|
|
Loading…
Reference in New Issue