discovery/kubernetes: Fix race in test setup

Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
pull/6834/head
Frederic Branczyk 5 years ago committed by Julien Pivotto
parent ef63d8d16d
commit d06f1034db

@ -65,6 +65,21 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
// Run discoverer and start a goroutine to read results.
go d.discovery.Run(ctx, ch)
// Ensure that discovery has a discoverer set. This prevents a race
// condition where the above go routine may or may not have set a
// discoverer yet.
for {
dis := d.discovery.(*Discovery)
dis.RLock()
l := len(dis.discoverers)
dis.RUnlock()
if l > 0 {
break
}
time.Sleep(10 * time.Millisecond)
}
resChan := make(chan map[string]*targetgroup.Group)
go readResultWithTimeout(t, ch, d.expectedMaxItems, time.Second, resChan)

Loading…
Cancel
Save