-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ package e2e | |
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -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)) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming that the two log statements were left intentionally There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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 { | ||
|
@@ -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. | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.