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 e3252f921a
commit 77ff9f680f
1 changed files with 12 additions and 17 deletions

View File

@ -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)
}
})
}