mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
discovery/kubernetes: Fix race in test setup
Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
This commit is contained in:
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…
Reference in a new issue