From e2aaa77d7aa2baf36b7a078751afd6200a515020 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:47:49 -0600 Subject: [PATCH] [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 https://github.com/open-telemetry/opentelemetry-collector/issues/10927 --- internal/e2e/status_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/e2e/status_test.go b/internal/e2e/status_test.go index c0ca4a6372b..67ac0721b13 100644 --- a/internal/e2e/status_test.go +++ b/internal/e2e/status_test.go @@ -35,6 +35,8 @@ import ( var nopType = component.MustNewType("nop") +var wg = sync.WaitGroup{} + func Test_ComponentStatusReporting_SharedInstance(t *testing.T) { eventsReceived := make(map[*componentstatus.InstanceID][]*componentstatus.Event) exporterFactory := exportertest.NewNopFactory() @@ -112,9 +114,10 @@ func Test_ComponentStatusReporting_SharedInstance(t *testing.T) { s, err := service.New(context.Background(), set, cfg) require.NoError(t, err) + wg.Add(1) err = s.Start(context.Background()) require.NoError(t, err) - time.Sleep(15 * time.Second) + wg.Wait() err = s.Shutdown(context.Background()) require.NoError(t, err) @@ -170,6 +173,7 @@ func (t *testReceiver) Start(_ context.Context, host component.Host) error { componentstatus.ReportStatus(host, componentstatus.NewRecoverableErrorEvent(errors.New("test recoverable error"))) go func() { componentstatus.ReportStatus(host, componentstatus.NewEvent(componentstatus.StatusOK)) + wg.Done() }() return nil } @@ -246,7 +250,6 @@ func createExtension(_ context.Context, _ extension.Settings, cfg component.Conf type testExtension struct { eventsReceived map[*componentstatus.InstanceID][]*componentstatus.Event - lock sync.Mutex } type extensionConfig struct { @@ -272,8 +275,6 @@ func (t *testExtension) ComponentStatusChanged( source *componentstatus.InstanceID, event *componentstatus.Event, ) { - t.lock.Lock() - defer t.lock.Unlock() if source.ComponentID() == component.NewID(component.MustNewType("test")) { t.eventsReceived[source] = append(t.eventsReceived[source], event) }