mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Add TestCoordinationWithEmptyProvider
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
48989d8996
commit
0798f14e02
|
@ -885,6 +885,31 @@ scrape_configs:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCoordinationWithEmptyProvider(t *testing.T) {
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
mgr := NewManager(ctx, nil)
|
||||||
|
mgr.updatert = 100 * time.Millisecond
|
||||||
|
go mgr.Run()
|
||||||
|
|
||||||
|
p := emptyProvider{}
|
||||||
|
mgr.StartCustomProvider(ctx, "empty", p)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("no update received in the expected timeframe")
|
||||||
|
case tgs, ok := <-mgr.SyncCh():
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("discovery manager channel is closed")
|
||||||
|
}
|
||||||
|
if len(tgs) != 0 {
|
||||||
|
t.Fatalf("target groups mismatch, got: %#v, expected: {}\n", tgs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCoordinationWithReceiver(t *testing.T) {
|
func TestCoordinationWithReceiver(t *testing.T) {
|
||||||
updateDelay := 100 * time.Millisecond
|
updateDelay := 100 * time.Millisecond
|
||||||
|
|
||||||
|
@ -1095,7 +1120,7 @@ func TestCoordinationWithReceiver(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.title, func(t *testing.T) {
|
t.Run(tc.title, func(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
mgr := NewManager(ctx, nil)
|
mgr := NewManager(ctx, nil)
|
||||||
|
@ -1109,21 +1134,25 @@ func TestCoordinationWithReceiver(t *testing.T) {
|
||||||
|
|
||||||
for i, expected := range tc.expected {
|
for i, expected := range tc.expected {
|
||||||
time.Sleep(expected.delay)
|
time.Sleep(expected.delay)
|
||||||
tgs, ok := <-mgr.SyncCh()
|
select {
|
||||||
if !ok {
|
case <-ctx.Done():
|
||||||
t.Fatal("discovery manager channel is closed")
|
t.Fatal("no update received in the expected timeframe")
|
||||||
}
|
case tgs, ok := <-mgr.SyncCh():
|
||||||
if len(tgs) != len(expected.tgs) {
|
if !ok {
|
||||||
t.Fatalf("step %d: target groups mismatch, got: %d, expected: %d\ngot: %#v\nexpected: %#v",
|
t.Fatal("discovery manager channel is closed")
|
||||||
i, len(tgs), len(expected.tgs), tgs, expected.tgs)
|
}
|
||||||
}
|
if len(tgs) != len(expected.tgs) {
|
||||||
for k := range expected.tgs {
|
t.Fatalf("step %d: target groups mismatch, got: %d, expected: %d\ngot: %#v\nexpected: %#v",
|
||||||
if _, ok := tgs[k]; !ok {
|
i, len(tgs), len(expected.tgs), tgs, expected.tgs)
|
||||||
t.Fatalf("step %d: target group not found: %s", i, k)
|
}
|
||||||
|
for k := range expected.tgs {
|
||||||
|
if _, ok := tgs[k]; !ok {
|
||||||
|
t.Fatalf("step %d: target group not found: %s", i, k)
|
||||||
|
}
|
||||||
|
assertEqualGroups(t, tgs[k], expected.tgs[k], func(got, expected string) string {
|
||||||
|
return fmt.Sprintf("step %d: targets mismatch \ngot: %q \nexpected: %q", i, got, expected)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
assertEqualGroups(t, tgs[k], expected.tgs[k], func(got, expected string) string {
|
|
||||||
return fmt.Sprintf("step %d: targets mismatch \ngot: %q \nexpected: %q", i, got, expected)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1176,3 +1205,10 @@ type byGroupSource []*targetgroup.Group
|
||||||
func (a byGroupSource) Len() int { return len(a) }
|
func (a byGroupSource) Len() int { return len(a) }
|
||||||
func (a byGroupSource) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a byGroupSource) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a byGroupSource) Less(i, j int) bool { return a[i].Source < a[j].Source }
|
func (a byGroupSource) Less(i, j int) bool { return a[i].Source < a[j].Source }
|
||||||
|
|
||||||
|
// emptyProvider sends no updates and closes the update channel.
|
||||||
|
type emptyProvider struct{}
|
||||||
|
|
||||||
|
func (e emptyProvider) Run(_ context.Context, ch chan<- []*targetgroup.Group) {
|
||||||
|
close(ch)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue