Skip to content

Commit e2aaa77

Browse files
authored
[chore] Fix flaky Test_ComponentStatusReporting_SharedInstance test (#11078)
#### Description Try adding wait group to ensure `StatusOk` is reported before the call to `Shutdown`. Passed with `go test status_test.go --count 2000` #### Link to tracking issue Fixes #10927
1 parent 35024cf commit e2aaa77

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/e2e/status_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import (
3535

3636
var nopType = component.MustNewType("nop")
3737

38+
var wg = sync.WaitGroup{}
39+
3840
func Test_ComponentStatusReporting_SharedInstance(t *testing.T) {
3941
eventsReceived := make(map[*componentstatus.InstanceID][]*componentstatus.Event)
4042
exporterFactory := exportertest.NewNopFactory()
@@ -112,9 +114,10 @@ func Test_ComponentStatusReporting_SharedInstance(t *testing.T) {
112114
s, err := service.New(context.Background(), set, cfg)
113115
require.NoError(t, err)
114116

117+
wg.Add(1)
115118
err = s.Start(context.Background())
116119
require.NoError(t, err)
117-
time.Sleep(15 * time.Second)
120+
wg.Wait()
118121
err = s.Shutdown(context.Background())
119122
require.NoError(t, err)
120123

@@ -170,6 +173,7 @@ func (t *testReceiver) Start(_ context.Context, host component.Host) error {
170173
componentstatus.ReportStatus(host, componentstatus.NewRecoverableErrorEvent(errors.New("test recoverable error")))
171174
go func() {
172175
componentstatus.ReportStatus(host, componentstatus.NewEvent(componentstatus.StatusOK))
176+
wg.Done()
173177
}()
174178
return nil
175179
}
@@ -246,7 +250,6 @@ func createExtension(_ context.Context, _ extension.Settings, cfg component.Conf
246250

247251
type testExtension struct {
248252
eventsReceived map[*componentstatus.InstanceID][]*componentstatus.Event
249-
lock sync.Mutex
250253
}
251254

252255
type extensionConfig struct {
@@ -272,8 +275,6 @@ func (t *testExtension) ComponentStatusChanged(
272275
source *componentstatus.InstanceID,
273276
event *componentstatus.Event,
274277
) {
275-
t.lock.Lock()
276-
defer t.lock.Unlock()
277278
if source.ComponentID() == component.NewID(component.MustNewType("test")) {
278279
t.eventsReceived[source] = append(t.eventsReceived[source], event)
279280
}

0 commit comments

Comments
 (0)