Skip to content

Commit

Permalink
fix: Give handler test time to process event (#242)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
There is a timing bug in the handler test where it occasionally doesn't
complete processing the event before it's closed. This makes the test
fail as libhoney didn't receive an event.

## Short description of the changes
- Add a time.sleep after adding an event to the event channel to give
the handler time to process it before starting shutdown
- Remove redundant `defer done()` as we intentionally call `done()` as
part of our shutdown processing

## How to verify that this has the expected result
The test no longer intermittently fails.
  • Loading branch information
MikeGoldsmith committed Sep 26, 2023
1 parent 2cb46ed commit 7c0e152
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion handlers/libhoney_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func Test_libhoneyEventHandler_handleEvent(t *testing.T) {
fakeCachedK8sClient := utils.NewCachedK8sClient(fake.NewSimpleClientset(srcPod, destPod))
cancelableCtx, done := context.WithCancel(context.Background())
fakeCachedK8sClient.Start(cancelableCtx)
defer done()

// create event channel used to pass in events to the handler
eventsChannel := make(chan assemblers.HttpEvent, 1)
Expand All @@ -86,6 +85,7 @@ func Test_libhoneyEventHandler_handleEvent(t *testing.T) {

// TEST ACTION: pass in httpEvent to handler
eventsChannel <- httpEvent
time.Sleep(10 * time.Millisecond) // give the handler time to process the event

done()
wgTest.Wait()
Expand Down

0 comments on commit 7c0e152

Please sign in to comment.