|
|
|
@ -128,7 +128,7 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resChan := make(chan map[string]*targetgroup.Group)
|
|
|
|
|
go readResultWithTimeout(t, ch, d.expectedMaxItems, time.Second, resChan)
|
|
|
|
|
go readResultWithTimeout(t, ctx, ch, d.expectedMaxItems, time.Second, resChan)
|
|
|
|
|
|
|
|
|
|
dd, ok := d.discovery.(hasSynced)
|
|
|
|
|
require.True(t, ok, "discoverer does not implement hasSynced interface")
|
|
|
|
@ -141,13 +141,18 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
|
|
|
|
|
if d.expectedRes != nil {
|
|
|
|
|
res := <-resChan
|
|
|
|
|
requireTargetGroups(t, d.expectedRes, res)
|
|
|
|
|
} else {
|
|
|
|
|
// Stop readResultWithTimeout and wait for it.
|
|
|
|
|
cancel()
|
|
|
|
|
<-resChan
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// readResultWithTimeout reads all targetgroups from channel with timeout.
|
|
|
|
|
// It merges targetgroups by source and sends the result to result channel.
|
|
|
|
|
func readResultWithTimeout(t *testing.T, ch <-chan []*targetgroup.Group, max int, timeout time.Duration, resChan chan<- map[string]*targetgroup.Group) {
|
|
|
|
|
func readResultWithTimeout(t *testing.T, ctx context.Context, ch <-chan []*targetgroup.Group, max int, stopAfter time.Duration, resChan chan<- map[string]*targetgroup.Group) {
|
|
|
|
|
res := make(map[string]*targetgroup.Group)
|
|
|
|
|
timeout := time.After(stopAfter)
|
|
|
|
|
Loop:
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
@ -162,12 +167,15 @@ Loop:
|
|
|
|
|
// Reached max target groups we may get, break fast.
|
|
|
|
|
break Loop
|
|
|
|
|
}
|
|
|
|
|
case <-time.After(timeout):
|
|
|
|
|
case <-timeout:
|
|
|
|
|
// Because we use queue, an object that is created then
|
|
|
|
|
// deleted or updated may be processed only once.
|
|
|
|
|
// So possibly we may skip events, timed out here.
|
|
|
|
|
t.Logf("timed out, got %d (max: %d) items, some events are skipped", len(res), max)
|
|
|
|
|
break Loop
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
t.Logf("stopped, got %d (max: %d) items", len(res), max)
|
|
|
|
|
break Loop
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|