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

[interna/sharedcomponent] Use a ring buffer to restrict remembered status count #11826

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test for hasEvent true
TylerHelmuth committed Dec 9, 2024
commit d1902c6566d215aa4100b76861d0878d64bac986
24 changes: 24 additions & 0 deletions internal/sharedcomponent/sharedcomponent_test.go
Original file line number Diff line number Diff line change
@@ -210,3 +210,27 @@ type testHost struct {
func (h *testHost) Report(e *componentstatus.Event) {
h.newStatusFunc(h.InstanceID, e)
}

func TestReportWithExistingEvent(t *testing.T) {
reportedStatuses := make([]componentstatus.Status, 0)
newStatusFunc := func(id *componentstatus.InstanceID, ev *componentstatus.Event) {
reportedStatuses = append(reportedStatuses, ev.Status())
}
base := &baseComponent{}
base.StartFunc = func(_ context.Context, host component.Host) error {
e := componentstatus.NewEvent(componentstatus.StatusOK)
componentstatus.ReportStatus(host, e)
componentstatus.ReportStatus(host, e)
return nil
}
comps := NewMap[component.ID, *baseComponent]()
comp, err := comps.LoadOrStore(
id,
func() (*baseComponent, error) { return base, nil },
)
require.NoError(t, err)
baseHost := componenttest.NewNopHost()
err = comp.Start(context.Background(), &testHost{Host: baseHost, InstanceID: &componentstatus.InstanceID{}, newStatusFunc: newStatusFunc})
require.NoError(t, err)
require.Equal(t, 3, len(reportedStatuses))
}