Skip to content

Commit ddd584f

Browse files
author
Kate Osborn
committed
Add swapAndHandleBatch func; fix unit test
1 parent b5befd8 commit ddd584f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

internal/events/events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func TestEventLoop_SwapBatches(t *testing.T) {
1111
eventLoop := NewEventLoop(nil, zap.New(), nil, nil)
1212

13-
eventLoop.currentBatch = []interface{}{
13+
eventLoop.currentBatch = EventBatch{
1414
"event0",
1515
"event1",
1616
"event2",

internal/events/loop.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func (el *EventLoop) Start(ctx context.Context) error {
7171
}(el.currentBatch)
7272
}
7373

74+
swapAndHandleBatch := func() {
75+
el.swapBatches()
76+
handleBatch()
77+
handling = true
78+
}
79+
7480
// Prepare the fist event batch, which includes the UpsertEvents for all relevant cluster resources.
7581
// This is necessary so that the first time the EventHandler generates NGINX configuration, it derives it from
7682
// a complete view of the cluster. Otherwise, the handler would generate incomplete configuration, which can lead
@@ -116,20 +122,14 @@ func (el *EventLoop) Start(ctx context.Context) error {
116122

117123
// If no batch is currently being handled, swap batches and begin handling the batch.
118124
if !handling {
119-
el.swapBatches()
120-
121-
handleBatch()
122-
handling = true
125+
swapAndHandleBatch()
123126
}
124127
case <-handlingDone:
125128
handling = false
126129

127130
// If there's at least one event in the next batch, swap batches and begin handling the batch.
128131
if len(el.nextBatch) > 0 {
129-
el.swapBatches()
130-
131-
handleBatch()
132-
handling = true
132+
swapAndHandleBatch()
133133
}
134134
}
135135
}

0 commit comments

Comments
 (0)