Skip to content

Commit

Permalink
closing after one message consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
yairsimantov20 committed Dec 20, 2023
1 parent d4816cd commit ae6ccad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/event_handler/consumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Fixture struct {

type MockConsumer struct {
pollData kafka.Event
close func()
}

func (m *MockConsumer) SubscribeTopics(topics []string, rebalanceCb kafka.RebalanceCb) (err error) {
Expand All @@ -36,6 +37,9 @@ func (m *MockConsumer) SubscribeTopics(topics []string, rebalanceCb kafka.Rebala
}

func (m *MockConsumer) Poll(timeoutMs int) (event kafka.Event) {
defer func() {
m.close()
}()
return m.pollData
}

Expand All @@ -50,6 +54,7 @@ func (m *MockConsumer) Close() (err error) {
func NewFixture(t *testing.T) *Fixture {
mock := &MockConsumer{}
consumer, err := NewConsumer(&config.KafkaConfiguration{}, mock)
mock.close = consumer.Close
if err != nil {
t.Fatalf("Error creating consumer: %v", err)
}
Expand Down

0 comments on commit ae6ccad

Please sign in to comment.