Skip to content

Commit

Permalink
[chore] Fix flaky Test_ComponentStatusReporting_SharedInstance test (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
TylerHelmuth committed Sep 6, 2024
1 parent 35024cf commit e2aaa77
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/e2e/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit e2aaa77

Please sign in to comment.