node-pm2-events
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "node-pm2-events", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "EventBus for local and decentralized instances of the both for individual nodejs applications and as parts of pm2", | ||
@@ -8,7 +8,9 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "npx tsd && npm run test:local && npm run test:transport", | ||
"test": "npx tsd && npm run test:local && npm run test:transport && npm run test:ws", | ||
"test:cluster": "node tests/eventbus-cluster-node.js.v.20.js", | ||
"test:local": "node tests/eventbus-local-process.js", | ||
"test:transport": "node tests/eventbus-transport-become-primary.js & node tests/eventbus-transport-become-primary.js", | ||
"test:tsd": "npx tsd" | ||
"test:ws": "node tests/eventbus-websocket-emul.test.js", | ||
"test:local": "node tests/eventbus-local-process.test.js", | ||
"test:transport": "node tests/eventbus-transport-become-primary.test.js & node tests/eventbus-transport-become-primary.test.js", | ||
"test:tsd": "npx tsd", | ||
"test:mocha": "mocha tests/*.test.js" | ||
}, | ||
@@ -15,0 +17,0 @@ "repository": { |
@@ -14,6 +14,7 @@ /* | ||
#warn = {}; | ||
addListener = this.on; | ||
removeListener = this.off; | ||
constructor() { | ||
this.addListener = this.on; | ||
this.removeListener = this.off; | ||
} | ||
@@ -20,0 +21,0 @@ |
@@ -336,4 +336,12 @@ /* | ||
}; | ||
/** | ||
* @param {boolean|null} reconnect | ||
*/ | ||
disconnect(reconnect) { | ||
this.#publisher.disconnect(false) | ||
this.#subscriber.disconnect(false) | ||
} | ||
} | ||
module.exports = Transport; |
@@ -146,2 +146,3 @@ /* | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
@@ -148,0 +149,0 @@ }); |
@@ -12,2 +12,4 @@ /* | ||
const {availableParallelism} = require('os'); | ||
const {describe, it} = require("node:test"); | ||
const assert = require("node:assert"); | ||
@@ -52,3 +54,3 @@ const numCPUs = Math.max(2, Math.min(2, availableParallelism())); | ||
// can be error with free redis service access | ||
//process.exit(1); | ||
process.exit(1); | ||
} | ||
@@ -96,7 +98,8 @@ } | ||
EventBus.setSendbox(true) | ||
await EventBus.transport.initialize(Config.redis) | ||
.filterByProcessName(false) | ||
.handshakes() | ||
EventBus.transport.setSendbox(true) | ||
EventBus.transport.on(channelName, (channelName, message) => { | ||
@@ -161,4 +164,5 @@ console.log(name, 'process', process.pid, EventBus.process.process_name, 'receive', message) | ||
const start = async () => { | ||
let statistic; | ||
if (cluster.isPrimary) { | ||
const statistic = new Statistics(); | ||
statistic = new Statistics(); | ||
registerProcessSignal('Cluster', statistic) | ||
@@ -175,9 +179,7 @@ for (let i = 0; i < numCPUs; i++) cluster.fork(); | ||
const name = 'Worker'; | ||
const statistic = new Statistics(); | ||
statistic = new Statistics(); | ||
registerProcessSignal(name, statistic) | ||
registerLocalEvents(name, statistic) | ||
await registerDecentralizedEvents(name, statistic) | ||
testLocalEvents(statistic) | ||
@@ -188,4 +190,11 @@ | ||
} | ||
describe('EventBus', () => { | ||
it('local events count', () => assert.equal(statistic.localReceive, 0)) | ||
it('local events count', () => assert.equal(statistic.localSent, 0)) | ||
it('local events count', () => assert.equal(statistic.transportReceive, 0)) | ||
it('local events count', () => assert.equal(statistic.transportSent, 0)) | ||
}) | ||
} | ||
start(); |
@@ -179,4 +179,6 @@ import EventBus = require("./EventBus"); | ||
toString(): string; | ||
disconnect(reconnect?: boolean): void; | ||
} | ||
//# sourceMappingURL=Transport.d.ts.map |
66577
37
1487
11