Add retries to StatsFetcherTest (#5892)

pull/5896/head
Freddy 2019-05-23 19:51:31 -04:00 committed by GitHub
parent 7e3cd36709
commit d4ea163b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 34 deletions

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/hashicorp/consul/agent/metadata"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/consul/testrpc"
"github.com/hashicorp/consul/types"
)
@ -47,6 +48,7 @@ func TestStatsFetcher(t *testing.T) {
// Do a normal fetch and make sure we get three responses.
func() {
retry.Run(t, func(r *retry.R) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
stats := s1.statsFetcher.Fetch(ctx, s1.LANMembers())
@ -65,11 +67,13 @@ func TestStatsFetcher(t *testing.T) {
t.Fatalf("bad: %#v", stat)
}
}
})
}()
// Fake an in-flight request to server 3 and make sure we don't fetch
// from it.
func() {
retry.Run(t, func(r *retry.R) {
s1.statsFetcher.inflight[string(s3.config.NodeID)] = struct{}{}
defer delete(s1.statsFetcher.inflight, string(s3.config.NodeID))
@ -93,5 +97,6 @@ func TestStatsFetcher(t *testing.T) {
t.Fatalf("bad: %#v", stat)
}
}
})
}()
}