Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Try fixing flaky SharedInstance e2e test #10929

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 42 additions & 28 deletions internal/e2e/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package e2e
import (
"context"
"errors"
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -101,31 +103,40 @@ func Test_ComponentStatusReporting_SharedInstance(t *testing.T) {
err = s.Shutdown(context.Background())
require.NoError(t, err)

assert.Equal(t, 5, len(eventsReceived))
require.Equal(t, 2, len(eventsReceived))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the value changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify the test I added a check in the test extension's ComponentStatusChanged function to only record events for the component the test cares about. This changed the number or recorded sources from 5 to 2.


for instanceID, events := range eventsReceived {
if instanceID.ComponentID() == component.NewID(component.MustNewType("test")) {
for i, e := range events {
if i == 0 {
assert.Equal(t, componentstatus.StatusStarting, e.Status())
}
if i == 1 {
assert.Equal(t, componentstatus.StatusRecoverableError, e.Status())
}
if i == 2 {
assert.Equal(t, componentstatus.StatusOK, e.Status())
}
if i == 3 {
assert.Equal(t, componentstatus.StatusStopping, e.Status())
}
if i == 4 {
assert.Equal(t, componentstatus.StatusStopped, e.Status())
}
if i >= 5 {
assert.Fail(t, "received too many events")
}
pipelineIDs := ""
instanceID.AllPipelineIDs(func(id component.ID) bool {
pipelineIDs += id.String() + ","
return true
})

t.Logf("checking errors for %v - %v - %v", pipelineIDs, instanceID.Kind().String(), instanceID.ComponentID().String())

eventStr := ""
for i, e := range events {
eventStr += fmt.Sprintf("%v,", e.Status())
if i == 0 {
assert.Equal(t, componentstatus.StatusStarting, e.Status())
}
if i == 1 {
assert.Equal(t, componentstatus.StatusRecoverableError, e.Status())
}
if i == 2 {
assert.Equal(t, componentstatus.StatusOK, e.Status())
}
if i == 3 {
assert.Equal(t, componentstatus.StatusStopping, e.Status())
}
if i == 4 {
assert.Equal(t, componentstatus.StatusStopped, e.Status())
}
if i >= 5 {
assert.Fail(t, "received too many events")
}
}
t.Logf("events received: %v", eventStr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming that the two log statements were left intentionally

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I added these so that in the future, if a flaky test comes back, it will be a little easier to debug.

}
}

Expand All @@ -141,12 +152,10 @@ func newReceiverFactory() receiver.Factory {
type testReceiver struct{}

func (t *testReceiver) Start(_ context.Context, host component.Host) error {
if statusReporter, ok := host.(componentstatus.Reporter); ok {
statusReporter.Report(componentstatus.NewRecoverableErrorEvent(errors.New("test recoverable error")))
go func() {
statusReporter.Report(componentstatus.NewEvent(componentstatus.StatusOK))
}()
}
componentstatus.ReportStatus(host, componentstatus.NewRecoverableErrorEvent(errors.New("test recoverable error")))
go func() {
componentstatus.ReportStatus(host, componentstatus.NewEvent(componentstatus.StatusOK))
}()
return nil
}

Expand Down Expand Up @@ -222,6 +231,7 @@ 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 @@ -247,7 +257,11 @@ func (t *testExtension) ComponentStatusChanged(
source *componentstatus.InstanceID,
event *componentstatus.Event,
) {
t.eventsReceived[source] = append(t.eventsReceived[source], event)
t.lock.Lock()
defer t.lock.Unlock()
if source.ComponentID() == component.NewID(component.MustNewType("test")) {
t.eventsReceived[source] = append(t.eventsReceived[source], event)
}
}

// NotifyConfig implements the extension.ConfigWatcher interface.
Expand Down
Loading