Skip to content

Commit

Permalink
ES6 Linting
Browse files Browse the repository at this point in the history
- changed var statements to const/let
- added dev dependency on @types/node to remove warnings from index.d.ts
- migrated istanbul to nyc coverage
- added package lock
  • Loading branch information
aricart committed Mar 27, 2019
1 parent 0b83c7e commit ce6bcef
Show file tree
Hide file tree
Showing 51 changed files with 1,113 additions and 947 deletions.
21 changes: 20 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"mocha": true,
"node": true
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ xunit.xml

logs/*
reports/*
tmp/*
tmp/*
coverage/*
.nyc_output/*
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ tmp/*
benchmark/
examples/
test/
coverage/
.istanbul.yml
.travis.yml
.eslintrc.js
.eslintignore
.nyc_output/
crockford.jscsrc
Makefile
TODO
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ language: node_js
sudo: false

node_js:
- "8"
- "10"
- "11"

cache: npm

git:
depth: false

env:
- NATS_VERSION=v1.3.0
- NATS_VERSION=v1.4.1

before_script:
- wget "https://github.com/nats-io/gnatsd/releases/download/$NATS_VERSION/gnatsd-$NATS_VERSION-linux-amd64.zip" -O tmp.zip
- unzip tmp.zip
- mv gnatsd-$NATS_VERSION-linux-amd64 gnatsd

script:
- if [[ "$TRAVIS_NODE_VERSION" == 6 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 8 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm run coveralls; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 11 ]]; then npm run coveralls; fi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A [Node.js](http://nodejs.org/) client for the [NATS messaging system](https://n
[![Build Status](https://travis-ci.org/nats-io/node-nats.svg?branch=master)](https://travis-ci.org/nats-io/node-nats)
[![Coveralls](https://img.shields.io/coveralls/github/nats-io/node-nats/master.svg)](https://coveralls.io/r/nats-io/node-nats?branch=master)
[![npm](https://img.shields.io/npm/v/nats.svg)](https://www.npmjs.com/package/nats)
[![npm](https://img.shields.io/npm/dt/nats.svg)](https://www.npmjs.com/package/nats)
[![npm](https://img.shields.io/npm/dm/nats.svg)](https://www.npmjs.com/package/nats)

## Installation
Expand Down Expand Up @@ -208,7 +209,7 @@ See examples for more usage.
```javascript
// Simple connect using credentials file. This loads JWT and signing key
// each time that NATS connects.
var nc = NATS.connect('connect.ngs.global', NATS.creds("./myid.creds");
var nc = NATS.connect('connect.ngs.global', NATS.creds("./myid.creds"));

// Setting nkey and signing callback directly.
var nc = NATS.connect(url, {
Expand Down
35 changes: 25 additions & 10 deletions benchmark/pub_perf.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

var NATS = require('../lib/nats');
var nats = NATS.connect();
var fs = require('fs');
const NATS = require('../lib/nats');
const nats = NATS.connect();
const fs = require('fs');

///////////////////////////////////////
// Publish Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
const loop = 1000000;
const hash = 2500;

console.log('Publish Performance Test');

nats.on('connect', function() {

var start = new Date();
const start = new Date();

var invalid2octet = Buffer.from('\xc3\x28', 'binary');
const invalid2octet = Buffer.from('\xc3\x28', 'binary');

for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nats.publish('test', invalid2octet);
//nats.publish('test', 'ok');
if (i % hash === 0) {
Expand All @@ -28,8 +43,8 @@ nats.on('connect', function() {
}

nats.flush(function() {
var stop = new Date();
var mps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const mps = parseInt(loop / ((stop - start) / 1000), 10);
log("pub", loop, stop - start);
console.log('\nPublished at ' + mps + ' msgs/sec');
});
Expand Down
37 changes: 26 additions & 11 deletions benchmark/pub_sub_perf.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

var fs = require('fs');
var NATS = require('../lib/nats');
var nc1 = NATS.connect();
var nc2 = NATS.connect();
const fs = require('fs');
const NATS = require('../lib/nats');
const nc1 = NATS.connect();
const nc2 = NATS.connect();

///////////////////////////////////////
// Publish/Subscribe Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
const loop = 1000000;
const hash = 2500;

console.log('Publish/Subscribe Performance Test');

nc1.on('connect', function() {

var received = 0;
var start = new Date();
let received = 0;
const start = new Date();

nc1.subscribe('test', function() {
received += 1;

if (received === loop) {
var stop = new Date();
var mps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const mps = parseInt(loop / ((stop - start) / 1000), 10);
console.log('\nPublished/Subscribe at ' + mps + ' msgs/sec');
console.log('Received ' + received + ' messages');
log("pubsub", loop, stop - start);
Expand All @@ -33,7 +48,7 @@ nc1.on('connect', function() {

// Make sure sub is registered
nc1.flush(function() {
for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc2.publish('test', 'ok');
if (i % hash === 0) {
process.stdout.write('+');
Expand Down
39 changes: 27 additions & 12 deletions benchmark/reconnect_perf.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";

var fs = require('fs');
var NATS = require('../lib/nats'),
const fs = require('fs');
const NATS = require('../lib/nats'),
nsc = require('../test/support/nats_server_control');


///////////////////////////////////////
// Reconnect Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
var PORT = 1426;
var server;
var start;
const loop = 1000000;
const hash = 2500;
const PORT = 1426;
let server;
let start;

console.log('Reconnect Performance Test');

server = nsc.start_server(PORT, function() {
var nc = NATS.connect({
const nc = NATS.connect({
'port': PORT
});
nc.on('connect', function() {
var fun = function() {
const fun = function () {
//do nothing
};
for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc.subscribe('test' + i, fun);
if (i % hash === 0) {
process.stdout.write('+');
Expand All @@ -39,8 +54,8 @@ server = nsc.start_server(PORT, function() {
});
nc.on('reconnect', function() {
nc.flush(function() {
var stop = new Date();
var t = stop - start;
const stop = new Date();
const t = stop - start;
console.log('\nReconnected in ' + t + ' ms');
nc.close();
server.kill();
Expand Down
41 changes: 28 additions & 13 deletions benchmark/request_perf.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
/*
* Copyright 2013-2019 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

"use strict";
var fs = require('fs');
var NATS = require('../lib/nats');
var nc1 = NATS.connect();
var nc2 = NATS.connect();
const fs = require('fs');
const NATS = require('../lib/nats');
const nc1 = NATS.connect();
const nc2 = NATS.connect();

///////////////////////////////////////
// Request Performance
///////////////////////////////////////

var loop = 100000;
var hash = 1000;
var received = 0;
const loop = 100000;
const hash = 1000;
let received = 0;

console.log('Request Performance Test');

nc1.on('connect', function() {

var start = new Date();
const start = new Date();

nc1.subscribe('request.test', function(msg, reply) {
nc1.publish(reply, 'ok');
Expand All @@ -25,17 +40,17 @@ nc1.on('connect', function() {
// Need to flush here since using separate connections.
nc1.flush(function() {

for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc2.request('request.test', 'help', {
'max': 1
}, function() {
received += 1;
if (received === loop) {
var stop = new Date();
var rps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const rps = parseInt(loop / ((stop - start) / 1000), 10);
console.log('\n' + rps + ' request-responses/sec');
var latmicros = ((stop - start) * 1000) / (loop * 2);
var lat = parseInt(latmicros, 10); // Request=2, Reponse=2 RTs
const latmicros = ((stop - start) * 1000) / (loop * 2);
const lat = parseInt(latmicros, 10); // Request=2, Reponse=2 RTs
console.log('Avg roundtrip latency: ' + lat + ' microseconds');
log("rr", loop, stop - start, latmicros);
} else if (received % hash === 0) {
Expand Down
Loading

0 comments on commit ce6bcef

Please sign in to comment.