Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mock sync producer does not handle the offset while sending messages #1747

Merged
merged 1 commit into from Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions mocks/sync_producer.go
Expand Up @@ -97,6 +97,8 @@ func (sp *SyncProducer) SendMessages(msgs []*sarama.ProducerMessage) error {
if expectation.Result != errProduceSuccess {
return expectation.Result
}
sp.lastOffset++
msgs[i].Offset = sp.lastOffset
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions mocks/sync_producer_test.go
Expand Up @@ -161,6 +161,13 @@ func TestSyncProducerWithCheckerFunctionForSendMessagesWithoutError(t *testing.T
t.Error("No error expected on SendMessages call, found: ", err)
}

for i, msg := range msgs {
offset := int64(i + 1)
if offset != msg.Offset {
t.Errorf("The message should have been assigned offset %d, but got %d", offset, msg.Offset)
}
}

if err := sp.Close(); err != nil {
t.Error(err)
}
Expand Down