From 1fca771b470665015d95543bfae21042badc5b93 Mon Sep 17 00:00:00 2001 From: Xiaoman Dong Date: Fri, 13 Apr 2018 14:24:10 -0700 Subject: [PATCH 1/5] 1.10.0 --- .travis.yml | 2 +- lib/kafka_base_producer.js | 4 ++-- package.json | 8 ++++++-- test/test_kafka_producer.js | 12 +++++++----- test/test_kafka_rest_client.js | 16 ++++++++-------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03bede2..b4037f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - '0.10.32' + - '6.10.0' notifications: email: diff --git a/lib/kafka_base_producer.js b/lib/kafka_base_producer.js index 6343538..4d193da 100644 --- a/lib/kafka_base_producer.js +++ b/lib/kafka_base_producer.js @@ -307,12 +307,12 @@ KafkaBaseProducer.prototype._produce = function _produce(msg, callback) { /* eslint-disable callback-return */ function onResponse(err, result) { + self.pendingWrites--; + if (callback) { callback(err, result); } - self.pendingWrites--; - if (self.closing) { self._tryClose(); } diff --git a/package.json b/package.json index 74b2313..c60e158 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kafka-rest-client", "description": "Kafka rest client to produce json/binary messages", - "version": "1.9.5", + "version": "1.10.0", "contributors": [ "Xiang Fu " ], @@ -50,8 +50,12 @@ "view-cover": "opn ./coverage/*/index.html" }, "engine": { - "node": ">= 0.10.x" + "node": ">= 6.10.0" }, + "engines": { + "node": "^6.10.0", + "npm": "4.0.5" + }, "pre-commit": [ "check-licence", "lint", diff --git a/test/test_kafka_producer.js b/test/test_kafka_producer.js index 667d59a..3ca08a5 100644 --- a/test/test_kafka_producer.js +++ b/test/test_kafka_producer.js @@ -456,7 +456,7 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser producer.connect(onConnect); function onConnect() { assert.equal(producer.producer.restClient.enable, true); - for (var i = 0; i < 5120000; i++) { + for (var i = 0; i < 5120; i++) { producer.produce('testTopic0', 'Important message', Date.now() / 1000.0); } producer.produce('testTopic1', 'Important message', Date.now() / 1000.0); @@ -491,7 +491,7 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser } /* eslint-enable block-scoped-var */ - assert.equal(cntTestTopic0, 5120000); + assert.equal(cntTestTopic0, 5120); assert.equal(cntTestTopic1, 2); assert.equal(cntTestTopic2, 3); assert.end(); @@ -500,9 +500,11 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser /* eslint-disable no-undef,block-scoped-var */ setTimeout(function stopTest1() { - server.stop(); producer.close(); - }, 2000); + setTimeout(function stopServer() { + server.stop(); + }, 20000); + }, 5000); /* eslint-enable no-undef,block-scoped-var */ } }); @@ -557,7 +559,7 @@ test('kafkaProducer handle no meta data situation', function testKafkaProducerHa function test2(next) { kafkaProducer.produce('hp_testTopic0', 'Important message', Date.now() / 1000.0, function assertErrorThrows2(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); } diff --git a/test/test_kafka_rest_client.js b/test/test_kafka_rest_client.js index 072b86b..9612613 100644 --- a/test/test_kafka_rest_client.js +++ b/test/test_kafka_rest_client.js @@ -50,7 +50,7 @@ function getProduceMessage(topic, message, ts, type) { test('KafkaRestClient can discover topics', function testKafkaRestClientTopicDiscovery(assert) { var configs = { proxyHost: 'localhost', - proxyPort: 4444, + proxyPort: 5555, proxyRefreshTime: 0 }; var restClient = new KafkaRestClient({ @@ -93,14 +93,14 @@ test('KafkaRestClient handle failed post with retries', function testKafkaRestCl function test1(next) { restClient.produce(getProduceMessage('testTopic0', 'msg0', timeStamp, 'binary'), function assertHttpErrorReason(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); }, function test2(next) { restClient.produce(getProduceMessage('hp.testTopic1', 'msg1', timeStamp, 'binary'), function assertErrorThrows(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); } @@ -110,7 +110,7 @@ test('KafkaRestClient handle failed post with retries', function testKafkaRestCl function test3(next) { restClient.produce(getProduceMessage('testTopic0', 'msg1', timeStamp, 'binary'), function assertErrorThrows(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); }, @@ -149,14 +149,14 @@ test('KafkaRestClient handle not cached topics', function testKafkaRestClientHan function test1(next) { restClient.produce(getProduceMessage('hp-testTopic-not-in-map', 'msg0', timeStamp, 'binary'), function assertErrorThrows(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); }, function test2(next) { restClient.produce(getProduceMessage('testTopic-not-in-map', 'msg0', timeStamp, 'binary'), function assertHttpErrorReason(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); server.start(); restClient.produce(getProduceMessage('testTopic-not-in-map', 'msg0', timeStamp, 'binary'), function assertHttpErrorReason2(err2) { @@ -190,14 +190,14 @@ test('KafkaRestClient handle post with blacklist client', function testKafkaRest function test1(next) { restClient.produce(getProduceMessage('testTopic0', 'msg0', timeStamp, 'binary'), function assertHttpErrorReason(err) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); next(); }); }, function test2(next) { restClient.produce(getProduceMessage('testTopic1', 'msg0', timeStamp, 'binary'), function assertErrorThrows(err, resp) { - assert.equal(err.reason, 'connect ECONNREFUSED'); + assert.true(err.reason.indexOf('connect ECONNREFUSED') >= 0); assert.equal(resp, undefined); next(); }); From 024631041eb7b9c152c87957cfba75f4e6bef17d Mon Sep 17 00:00:00 2001 From: Xiaoman Dong Date: Mon, 16 Apr 2018 23:52:10 -0700 Subject: [PATCH 2/5] try handling exception correctly --- .travis.yml | 2 ++ package.json | 8 ++++---- test/test_kafka_producer.js | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index b4037f1..1d33a12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,5 @@ node_js: notifications: email: - xiangfu@uber.com + +before_install: if [[ `npm -v` != 2* ]]; then npm i -g npm@2; fi \ No newline at end of file diff --git a/package.json b/package.json index c60e158..c006785 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dependencies": { "@sinonjs/formatio": "^2.0.0", "error": "^7.0.1", - "lb_pool": "^1.2.0", + "lb_pool": "^1.7.1", "pkginfo": "^0.4.1", "sinon": "^4.5.0" }, @@ -50,11 +50,11 @@ "view-cover": "opn ./coverage/*/index.html" }, "engine": { - "node": ">= 6.10.0" + "node": ">= 0.10.32" }, "engines": { - "node": "^6.10.0", - "npm": "4.0.5" + "node": "^0.10.32", + "npm": "2.15.11" }, "pre-commit": [ "check-licence", diff --git a/test/test_kafka_producer.js b/test/test_kafka_producer.js index 3ca08a5..18c43ef 100644 --- a/test/test_kafka_producer.js +++ b/test/test_kafka_producer.js @@ -450,13 +450,15 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser proxyHost: 'localhost', proxyPort: PORT, enableAudit: true, - auditTimeBucketIntervalInSec: 1 + auditTimeBucketIntervalInSec: 1, + timeout: 0, + maxRetries: 0 }; var producer = new KafkaProducer(configs); producer.connect(onConnect); function onConnect() { assert.equal(producer.producer.restClient.enable, true); - for (var i = 0; i < 5120; i++) { + for (var i = 0; i < 512000; i++) { producer.produce('testTopic0', 'Important message', Date.now() / 1000.0); } producer.produce('testTopic1', 'Important message', Date.now() / 1000.0); @@ -491,7 +493,7 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser } /* eslint-enable block-scoped-var */ - assert.equal(cntTestTopic0, 5120); + assert.equal(cntTestTopic0, 512000); assert.equal(cntTestTopic1, 2); assert.equal(cntTestTopic2, 3); assert.end(); @@ -499,11 +501,9 @@ test('Test generate audit msg', function testKafkaProducerGenerateAuditMsg(asser /* eslint-enable camelcase */ /* eslint-disable no-undef,block-scoped-var */ + server.stop(); setTimeout(function stopTest1() { producer.close(); - setTimeout(function stopServer() { - server.stop(); - }, 20000); }, 5000); /* eslint-enable no-undef,block-scoped-var */ } From 2cd2341ac6cc82fb9e7e5a5fa97e7e02e3dc4c68 Mon Sep 17 00:00:00 2001 From: Xiaoman Dong Date: Mon, 16 Apr 2018 23:55:46 -0700 Subject: [PATCH 3/5] node 0.10.32 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d33a12..5bedb90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - '6.10.0' + - '0.10.32' notifications: email: From 40aa9aabd0a6f47eab3ac4e846de3c12c33c204d Mon Sep 17 00:00:00 2001 From: Xiaoman Dong Date: Tue, 17 Apr 2018 00:02:58 -0700 Subject: [PATCH 4/5] try fixing version --- .travis.yml | 5 ++++- package.json | 2 +- test/test_kafka_rest_client.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bedb90..39384a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,7 @@ notifications: email: - xiangfu@uber.com -before_install: if [[ `npm -v` != 2* ]]; then npm i -g npm@2; fi \ No newline at end of file +before_install: + - if [[ `npm -v` != 2* ]]; then npm i -g npm@2; fi + - npm -v + - node -v \ No newline at end of file diff --git a/package.json b/package.json index c006785..18f1883 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "opn": "^0.1.2", "pre-commit": "0.0.9", "proxyquire": "*", - "rewire": "*", + "rewire": "3.0.2", "should": "*", "sinon": "*", "tape": "^4.2.0", diff --git a/test/test_kafka_rest_client.js b/test/test_kafka_rest_client.js index 9612613..80304eb 100644 --- a/test/test_kafka_rest_client.js +++ b/test/test_kafka_rest_client.js @@ -50,7 +50,7 @@ function getProduceMessage(topic, message, ts, type) { test('KafkaRestClient can discover topics', function testKafkaRestClientTopicDiscovery(assert) { var configs = { proxyHost: 'localhost', - proxyPort: 5555, + proxyPort: 4444, proxyRefreshTime: 0 }; var restClient = new KafkaRestClient({ From 544953233dd831bbf3aa381c2f56cf85eacee2ea Mon Sep 17 00:00:00 2001 From: Xiaoman Dong Date: Tue, 17 Apr 2018 10:26:25 -0700 Subject: [PATCH 5/5] remove debugging travis line --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39384a8..174b998 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,4 @@ notifications: - xiangfu@uber.com before_install: - - if [[ `npm -v` != 2* ]]; then npm i -g npm@2; fi - - npm -v - - node -v \ No newline at end of file + - if [[ `npm -v` != 2* ]]; then npm i -g npm@2; fi \ No newline at end of file