rpc: fix TestReadyForConsistentRead

timing was too tight. Standardized name.
This commit is contained in:
Frank Schroeder 2017-06-26 13:35:24 +02:00 committed by Frank Schröder
parent fcab525053
commit ff2c29c0be

View File

@ -9,6 +9,7 @@ import (
"github.com/hashicorp/consul/agent/consul/state" "github.com/hashicorp/consul/agent/consul/state"
"github.com/hashicorp/consul/agent/consul/structs" "github.com/hashicorp/consul/agent/consul/structs"
"github.com/hashicorp/consul/testrpc" "github.com/hashicorp/consul/testrpc"
"github.com/hashicorp/consul/testutil/retry"
"github.com/hashicorp/go-memdb" "github.com/hashicorp/go-memdb"
"github.com/hashicorp/net-rpc-msgpackrpc" "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) { dir, s := testServerWithConfig(t, func(c *Config) {
c.RPCHoldTimeout = 2 * time.Millisecond c.RPCHoldTimeout = 2 * time.Millisecond
}) })
@ -178,26 +180,19 @@ func TestReadyForConsistentReads(t *testing.T) {
} }
s.resetConsistentReadReady() 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() err := s.consistentRead()
if err.Error() != "Not ready to serve consistent reads" { if err.Error() != "Not ready to serve consistent reads" {
t.Fatal("Server should NOT be ready for 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 { go func() {
t.Fatalf("Expected server to be ready for consistent reads, got error %v", err) 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)
}
})
} }