Skip to content

Commit

Permalink
Merge pull request #1747 from XSAM/fix/mocks-sync-producer
Browse files Browse the repository at this point in the history
fix: mock sync producer does not handle the offset while sending messages
  • Loading branch information
d1egoaz committed Jan 12, 2021
2 parents 2a5254c + 95b78dd commit 80667b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 80667b9

Please sign in to comment.