diff --git a/agent/consul/rpc_test.go b/agent/consul/rpc_test.go index 959967987..890ff81f9 100644 --- a/agent/consul/rpc_test.go +++ b/agent/consul/rpc_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/consul/agent/consul/state" "github.com/hashicorp/consul/agent/consul/structs" "github.com/hashicorp/consul/testrpc" + "github.com/hashicorp/consul/testutil/retry" "github.com/hashicorp/go-memdb" "github.com/hashicorp/net-rpc-msgpackrpc" ) @@ -164,7 +165,8 @@ func TestRPC_blockingQuery(t *testing.T) { } } -func TestReadyForConsistentReads(t *testing.T) { +func TestRPC_ReadyForConsistentReads(t *testing.T) { + t.Parallel() dir, s := testServerWithConfig(t, func(c *Config) { c.RPCHoldTimeout = 2 * time.Millisecond }) @@ -178,26 +180,19 @@ func TestReadyForConsistentReads(t *testing.T) { } s.resetConsistentReadReady() - - setConsistentFunc := func() { - time.Sleep(3 * time.Millisecond) - s.setConsistentReadReady() - } - - go setConsistentFunc() - - //set some time to wait for the goroutine above to finish - waitUntil := time.Now().Add(time.Millisecond * 5) err := s.consistentRead() if err.Error() != "Not ready to serve consistent reads" { t.Fatal("Server should NOT be ready for consistent reads") } - for time.Now().Before(waitUntil) && err != nil { - err = s.consistentRead() - } - if err != nil { - t.Fatalf("Expected server to be ready for consistent reads, got error %v", err) - } + go func() { + time.Sleep(100 * time.Millisecond) + s.setConsistentReadReady() + }() + retry.Run(t, func(r *retry.R) { + if err := s.consistentRead(); err != nil { + r.Fatalf("Expected server to be ready for consistent reads, got error %v", err) + } + }) }