Skip to content

Commit

Permalink
fix(logs): reset eventChan everytime KarmorLogStart() is called
Browse files Browse the repository at this point in the history
This will reduce flakiness in the tests

Signed-off-by: Navin Chandra <navinchandra772@gmail.com>
  • Loading branch information
navin772 authored and Prateeknandle committed Jul 11, 2024
1 parent ffb252f commit 74e9772
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/util/karmorlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,25 @@ func KarmorGetTargetAlert(timeout time.Duration, target *pb.Alert) (EventResult,
return res, nil
}

// drainEventChan drains all events from the eventChan.
func drainEventChan() {
if eventChan == nil {
return
}
for {
select {
case <-eventChan:
default:
return
}
}
}

// KarmorLogStart start observing for kubearmor telemetry events
func KarmorLogStart(logFilter string, ns string, op string, pod string) error {
// reset eventChan
drainEventChan()

if eventChan == nil {
eventChan = make(chan klog.EventInfo, maxEvents)
}
Expand Down

0 comments on commit 74e9772

Please sign in to comment.