mirror of https://github.com/hashicorp/consul
agent/grpc: fix a flaky test by performing more retries
Instead of using retry.Run, which appears to have problems in some cases where it does not emit an error message, use a for loop. Increase the number of attempts and remove any sleep, since this operation is not that expensive to do in a tight looppull/8961/head
parent
df405ac978
commit
d19657404f
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/grpc/internal/testservice"
|
"github.com/hashicorp/consul/agent/grpc/internal/testservice"
|
||||||
"github.com/hashicorp/consul/agent/grpc/resolver"
|
"github.com/hashicorp/consul/agent/grpc/resolver"
|
||||||
"github.com/hashicorp/consul/agent/metadata"
|
"github.com/hashicorp/consul/agent/metadata"
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDialer_WithTLSWrapper(t *testing.T) {
|
func TestNewDialer_WithTLSWrapper(t *testing.T) {
|
||||||
|
@ -84,7 +83,7 @@ func newScheme(n string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientConnPool_IntegrationWithGRPCResolver_Rebalance(t *testing.T) {
|
func TestClientConnPool_IntegrationWithGRPCResolver_Rebalance(t *testing.T) {
|
||||||
count := 4
|
count := 5
|
||||||
cfg := resolver.Config{Scheme: newScheme(t.Name())}
|
cfg := resolver.Config{Scheme: newScheme(t.Name())}
|
||||||
res := resolver.NewServerResolverBuilder(cfg)
|
res := resolver.NewServerResolverBuilder(cfg)
|
||||||
resolver.RegisterWithGRPC(res)
|
resolver.RegisterWithGRPC(res)
|
||||||
|
@ -118,13 +117,17 @@ func TestClientConnPool_IntegrationWithGRPCResolver_Rebalance(t *testing.T) {
|
||||||
t.Run("rebalance the dc", func(t *testing.T) {
|
t.Run("rebalance the dc", func(t *testing.T) {
|
||||||
// Rebalance is random, but if we repeat it a few times it should give us a
|
// Rebalance is random, but if we repeat it a few times it should give us a
|
||||||
// new server.
|
// new server.
|
||||||
retry.RunWith(fastRetry, t, func(r *retry.R) {
|
attempts := 100
|
||||||
|
for i := 0; i < attempts; i++ {
|
||||||
res.NewRebalancer("dc1")()
|
res.NewRebalancer("dc1")()
|
||||||
|
|
||||||
resp, err := client.Something(ctx, &testservice.Req{})
|
resp, err := client.Something(ctx, &testservice.Req{})
|
||||||
require.NoError(r, err)
|
require.NoError(t, err)
|
||||||
require.NotEqual(r, resp.ServerName, first.ServerName)
|
if resp.ServerName != first.ServerName {
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Fatalf("server was not rebalanced after %v attempts", attempts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/grpc/internal/testservice"
|
"github.com/hashicorp/consul/agent/grpc/internal/testservice"
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func noopRegister(*grpc.Server) {}
|
func noopRegister(*grpc.Server) {}
|
||||||
|
@ -93,8 +92,6 @@ func TestHandler_EmitsStats(t *testing.T) {
|
||||||
assertDeepEqual(t, expectedCounter, sink.incrCounterCalls, cmpMetricCalls)
|
assertDeepEqual(t, expectedCounter, sink.incrCounterCalls, cmpMetricCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fastRetry = &retry.Timer{Timeout: 7 * time.Second, Wait: 2 * time.Millisecond}
|
|
||||||
|
|
||||||
func assertDeepEqual(t *testing.T, x, y interface{}, opts ...cmp.Option) {
|
func assertDeepEqual(t *testing.T, x, y interface{}, opts ...cmp.Option) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if diff := cmp.Diff(x, y, opts...); diff != "" {
|
if diff := cmp.Diff(x, y, opts...); diff != "" {
|
||||||
|
|
Loading…
Reference in New Issue