diff --git a/lib/protocol/protocol.js b/lib/protocol/protocol.js index 445c10e2..22b22d56 100644 --- a/lib/protocol/protocol.js +++ b/lib/protocol/protocol.js @@ -1127,6 +1127,9 @@ function decodeOffsetResponse (resp) { function decodeOffsets (end, vars) { if (--vars.offsetNum <= 0) end(); topics[vars.topic][vars.partition] = topics[vars.topic][vars.partition] || []; + if (vars.offsetNum < 0) { + return; + } this.word64bs('offset').tap(function (vars) { if (vars.offset != null) topics[vars.topic][vars.partition].push(vars.offset); }); diff --git a/test/test.offset.js b/test/test.offset.js index 98aaec4f..a497e6a1 100644 --- a/test/test.offset.js +++ b/test/test.offset.js @@ -14,7 +14,7 @@ describe('Offset', function () { client = new Client(); producer = new Producer(client); producer.on('ready', function () { - producer.createTopics(['_exist_topic_3_test'], true, function (err) { + producer.createTopics(['_exist_topic_3_test', '_exist_topic_4_test'], true, function (err) { done(err); }); }); @@ -38,6 +38,20 @@ describe('Offset', function () { }); }); + it('should return empty offsets list by old timestamp', function (done) { + var firstTopic = '_exist_topic_3_test'; + var secondTopic = '_exist_topic_4_test'; + var fakeTime = new Date('2019-05-16').getTime(); + var topics = [{ topic: firstTopic, time: fakeTime }, { topic: secondTopic, time: fakeTime }]; + offset.fetch(topics, function (err, data) { + var firstOffsets = data[firstTopic][0]; + var secondOffsets = data[secondTopic][0]; + firstOffsets.should.be.an.instanceOf(Array); + secondOffsets.should.be.an.instanceOf(Array); + done(err); + }); + }); + it('should return earliest offset of the topics', function (done) { var topic = '_exist_topic_3_test'; var topics = [{ topic: topic, time: -2 }];