mirror of https://github.com/hashicorp/consul
Add retries to StatsFetcherTest (#5892)
parent
7e3cd36709
commit
d4ea163b0b
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/metadata"
|
"github.com/hashicorp/consul/agent/metadata"
|
||||||
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/hashicorp/consul/testrpc"
|
||||||
"github.com/hashicorp/consul/types"
|
"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.
|
// Do a normal fetch and make sure we get three responses.
|
||||||
func() {
|
func() {
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
stats := s1.statsFetcher.Fetch(ctx, s1.LANMembers())
|
stats := s1.statsFetcher.Fetch(ctx, s1.LANMembers())
|
||||||
|
@ -65,11 +67,13 @@ func TestStatsFetcher(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", stat)
|
t.Fatalf("bad: %#v", stat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Fake an in-flight request to server 3 and make sure we don't fetch
|
// Fake an in-flight request to server 3 and make sure we don't fetch
|
||||||
// from it.
|
// from it.
|
||||||
func() {
|
func() {
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
s1.statsFetcher.inflight[string(s3.config.NodeID)] = struct{}{}
|
s1.statsFetcher.inflight[string(s3.config.NodeID)] = struct{}{}
|
||||||
defer delete(s1.statsFetcher.inflight, string(s3.config.NodeID))
|
defer delete(s1.statsFetcher.inflight, string(s3.config.NodeID))
|
||||||
|
|
||||||
|
@ -93,5 +97,6 @@ func TestStatsFetcher(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", stat)
|
t.Fatalf("bad: %#v", stat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue