Skip to content

Commit

Permalink
Test coverage for null or empty message value or key (issue #36) (#99)
Browse files Browse the repository at this point in the history
* Test coverage for null or empty message value or key

This verifies the fix for #36

Developed with @mimaison

* Fixed missing clearInterval() calls

* Tweaked ordering
  • Loading branch information
edoardocomar authored and webmakersteve committed Jan 19, 2017
1 parent b351df3 commit 05cfe56
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions e2e/both.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var t = require('assert');
var Kafka = require('../');
var kafkaBrokerList = process.env.KAFKA_HOST || 'localhost:9092';
var eventListener = require('./listener');
var topic = 'test';

describe('Consumer/Producer', function() {

Expand Down Expand Up @@ -76,7 +77,6 @@ describe('Consumer/Producer', function() {

it('should be able to produce, consume messages, read position: subscribe/consumeOnce', function(done) {
this.timeout(20000);
var topic = 'test';

crypto.randomBytes(4096, function(ex, buffer) {

Expand Down Expand Up @@ -130,7 +130,6 @@ describe('Consumer/Producer', function() {

it('should be able to produce and consume messages: consumeLoop', function(done) {
this.timeout(20000);
var topic = 'test';
var key = 'key';

crypto.randomBytes(4096, function(ex, buffer) {
Expand Down Expand Up @@ -165,4 +164,50 @@ describe('Consumer/Producer', function() {
});
});

it('should be able to produce and consume messages: empty key and empty value', function(done) {
this.timeout(20000);
var key = '';
var value = new Buffer('');

var tt = setInterval(function() {
producer.poll();
}, 100);

consumer.once('data', function(message) {
clearInterval(tt);
t.equal(value.toString(), message.value.toString(), 'invalid message value');
t.equal(key, message.key, 'invalid message key');
done();
});

consumer.consume([topic]);

setTimeout(function() {
producer.produce(topic, null, value, key);
}, 2000);
});

it('should be able to produce and consume messages: null key and null value', function(done) {
this.timeout(20000);
var key = null;
var value = null;

var tt = setInterval(function() {
producer.poll();
}, 100);

consumer.once('data', function(message) {
clearInterval(tt);
t.equal(value, message.value, 'invalid message value');
t.equal(key, message.key, 'invalid message key');
done();
});

consumer.consume([topic]);

setTimeout(function() {
producer.produce(topic, null, value, key);
}, 2000);
});

});

0 comments on commit 05cfe56

Please sign in to comment.