MCPcopy
hub / github.com/kubernetes/client-go / TestEventCorrelator

Function TestEventCorrelator

tools/record/events_cache_test.go:162–279  ·  view source on GitHub ↗

TestEventCorrelator validates proper counting, aggregation of events

(t *testing.T)

Source from the content-addressed store, hash-verified

160
161// TestEventCorrelator validates proper counting, aggregation of events
162func TestEventCorrelator(t *testing.T) {
163 firstEvent := makeEvent("first", "i am first", makeObjectReference("Pod", "my-pod", "my-ns"))
164 duplicateEvent := makeEvent("duplicate", "me again", makeObjectReference("Pod", "my-pod", "my-ns"))
165 uniqueEvent := makeEvent("unique", "snowflake", makeObjectReference("Pod", "my-pod", "my-ns"))
166 similarEvent := makeEvent("similar", "similar message", makeObjectReference("Pod", "my-pod", "my-ns"))
167 similarEvent.InvolvedObject.FieldPath = "spec.containers{container1}"
168 aggregateEvent := makeEvent(similarEvent.Reason, EventAggregatorByReasonMessageFunc(&similarEvent), similarEvent.InvolvedObject)
169 similarButDifferentContainerEvent := similarEvent
170 similarButDifferentContainerEvent.InvolvedObject.FieldPath = "spec.containers{container2}"
171 scenario := map[string]struct {
172 previousEvents []v1.Event
173 newEvent v1.Event
174 expectedEvent v1.Event
175 intervalSeconds int
176 expectedSkip bool
177 }{
178 "create-a-single-event": {
179 previousEvents: []v1.Event{},
180 newEvent: firstEvent,
181 expectedEvent: setCount(firstEvent, 1),
182 intervalSeconds: 5,
183 },
184 "the-same-event-should-just-count": {
185 previousEvents: makeEvents(1, duplicateEvent),
186 newEvent: duplicateEvent,
187 expectedEvent: setCount(duplicateEvent, 2),
188 intervalSeconds: 5,
189 },
190 "the-same-event-should-just-count-even-if-more-than-aggregate": {
191 previousEvents: makeEvents(defaultAggregateMaxEvents, duplicateEvent),
192 newEvent: duplicateEvent,
193 expectedEvent: setCount(duplicateEvent, defaultAggregateMaxEvents+1),
194 intervalSeconds: 30, // larger interval induces aggregation but not spam.
195 },
196 "the-same-event-is-spam-if-happens-too-frequently": {
197 previousEvents: makeEvents(defaultSpamBurst+1, duplicateEvent),
198 newEvent: duplicateEvent,
199 expectedSkip: true,
200 intervalSeconds: 1,
201 },
202 "create-many-unique-events": {
203 previousEvents: makeUniqueEvents(30),
204 newEvent: uniqueEvent,
205 expectedEvent: setCount(uniqueEvent, 1),
206 intervalSeconds: 5,
207 },
208 "similar-events-should-aggregate-event": {
209 previousEvents: makeSimilarEvents(defaultAggregateMaxEvents-1, similarEvent, similarEvent.Message),
210 newEvent: similarEvent,
211 expectedEvent: setCount(aggregateEvent, 1),
212 intervalSeconds: 5,
213 },
214 "similar-events-many-times-should-count-the-aggregate": {
215 previousEvents: makeSimilarEvents(defaultAggregateMaxEvents, similarEvent, similarEvent.Message),
216 newEvent: similarEvent,
217 expectedEvent: setCount(aggregateEvent, 2),
218 intervalSeconds: 5,
219 },

Callers

nothing calls this directly

Calls 13

EventCorrelateMethod · 0.95
UpdateStateMethod · 0.95
makeEventFunction · 0.85
makeObjectReferenceFunction · 0.85
setCountFunction · 0.85
makeEventsFunction · 0.85
makeUniqueEventsFunction · 0.85
makeSimilarEventsFunction · 0.85
NewEventCorrelatorFunction · 0.85
validateEventFunction · 0.85
NowMethod · 0.65

Tested by

no test coverage detected