From 194b55af191fe5f6f5be8e89815a0a4b6140504a Mon Sep 17 00:00:00 2001 From: zhongyu Date: Thu, 14 Nov 2013 13:49:34 +0800 Subject: [PATCH] fixed --- lib/producer.js | 2 +- test/test.producer.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/producer.js b/lib/producer.js index 25fd8044..132ff2b8 100644 --- a/lib/producer.js +++ b/lib/producer.js @@ -64,7 +64,7 @@ Producer.prototype.createTopics = function (topics, async, cb) { return; } topics = typeof topic === 'string' ? [topics] : topics; - if (typeof async === 'function' || typeof async === 'undefined') { + if (typeof async === 'function' && typeof cb === 'undefined') { cb = async; async = true; } diff --git a/test/test.producer.js b/test/test.producer.js index 7c6471cd..57955a20 100644 --- a/test/test.producer.js +++ b/test/test.producer.js @@ -1,11 +1,15 @@ 'use strict'; -var libPath = process.env['kafka-cov'] ? '../lib-cov/' : '../lib/', - Producer = require(libPath + 'producer'), - Client = require(libPath + 'client'); +var Producer = require('../lib/producer'), + Client = require('../lib/client'); var client, producer; +// Helper method +function randomId () { + return Math.floor(Math.random() * 10000) +} + before(function (done) { client = new Client(); producer = new Producer(client); @@ -35,14 +39,21 @@ describe('Producer', function () { describe('#createTopics', function () { it('should return All requests sent when async is true', function (done) { - producer.createTopics(['_exist_topic_4_test'], function (err, data) { + producer.createTopics(['_exist_topic_'+ randomId() +'_test'], true, function (err, data) { + data.should.equal('All requests sent'); + done(err); + }); + }); + + it('async should be true if not present', function (done) { + producer.createTopics(['_exist_topic_'+ randomId() +'_test'], function (err, data) { data.should.equal('All requests sent'); done(err); }); }); it('should return All created when async is false', function (done) { - producer.createTopics(['_exist_topic_4_test'], false, function (err, data) { + producer.createTopics(['_exist_topic_'+ randomId() +'_test'], false, function (err, data) { data.should.equal('All created'); done(err); });