Skip to content

Commit 9454839

Browse files
committed
cluster events docs, cluster events tests
1 parent 237912f commit 9454839

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

docs/clustering.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ createCluster({
122122
123123
### Events
124124

125-
The Node Redis cluster class is an Nodejs EventEmitter and emits following events:
125+
The Node Redis Cluster class extends Node.js’s EventEmitter and emits the following events:
126126

127127
| Name | When | Listener arguments |
128128
| ----------------------- | ---------------------------------------------------------------------------------- | --------------------------------------------------------- |
129-
| `connect` | The cluster connected and ready to use | _No arguments_ |
129+
| `connect` | The cluster has successfully connected and is ready to us | _No arguments_ |
130130
| `disconnect` | The cluster has disconnected | _No arguments_ |
131131
| `error` | The cluster has errored | `(error: Error)` |
132-
| `node-connect` | One of the cluster's nodes has connected | `(node: { host: string, port: number })` |
133-
| `node-disconnect` | One of the cluster's nodes has disconnected | `(node: { host: string, port: number })` |
134-
| `node-ready` | One of the cluster's nodes is ready to connect | `(node: { host: string, port: number })` |
135-
| `node-reconnecting` | One of the cluster's nodes is trying to reconnect after error has occurred | `(node: { host: string, port: number })` |
136-
| `node-error` | One of the cluster's nodes has errored, usually during TCP connection | `(error: Error, node: { host: string, port: number }` |
132+
| `node-ready` | A cluster node is ready to establish a connection | `(node: { host: string, port: number })` |
133+
| `node-connect` | A cluster node has connected | `(node: { host: string, port: number })` |
134+
| `node-reconnecting` | A cluster node is attempting to reconnect after an error | `(node: { host: string, port: number })` |
135+
| `node-disconnect` | A cluster node has disconnected | `(node: { host: string, port: number })` |
136+
| `node-error` | A cluster node has has errored (usually during TCP connection) | `(error: Error, node: { host: string, port: number })` |
137137

138138
> :warning: You **MUST** listen to `error` events. If a cluster doesn't have at least one `error` listener registered and
139139
> an `error` occurs, that error will be thrown and the Node.js process will exit. See the [ > `EventEmitter` docs](https://nodejs.org/api/events.html#events_error_events) for more details.

packages/client/lib/cluster/index.spec.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ describe('Cluster', () => {
343343
describe('clusterEvents', () => {
344344
testUtils.testWithCluster('should fire events', async (cluster) => {
345345
const log: string[] = [];
346-
const rootNodes = cluster._options.rootNodes.length;
347-
const nodeConnect = rootNodes;
348-
const nodeReady = nodeConnect + rootNodes;
346+
const { numberOfMasters } = GLOBAL.CLUSTERS.WITH_REPLICAS;
347+
const nodeConnect = numberOfMasters;
348+
const nodeReady = nodeConnect + numberOfMasters;
349349
const connect = nodeReady + 1;
350-
const nodeDisconnect = connect + rootNodes;
350+
const nodeDisconnect = connect + numberOfMasters;
351351
const disconnect = nodeDisconnect + 1;
352352

353353
cluster
@@ -363,38 +363,37 @@ describe('Cluster', () => {
363363
await cluster.connect();
364364
cluster.destroy();
365365

366-
assert.strictEqual(log.length, disconnect);
366+
assert.equal(log.length, disconnect);
367367

368-
assert.deepStrictEqual(
368+
assert.deepEqual(
369369
log.slice(0, nodeConnect),
370-
new Array(rootNodes).fill('node-connect'),
370+
new Array(numberOfMasters).fill('node-connect'),
371371
);
372-
assert.deepStrictEqual(
372+
assert.deepEqual(
373373
log.slice(nodeConnect, nodeReady),
374-
new Array(rootNodes).fill('node-ready'),
374+
new Array(numberOfMasters).fill('node-ready'),
375375
);
376-
assert.deepStrictEqual(
376+
assert.deepEqual(
377377
log.slice(nodeReady, connect),
378378
new Array(1).fill('connect'),
379379
);
380-
assert.deepStrictEqual(
380+
assert.deepEqual(
381381
log.slice(connect, nodeDisconnect),
382-
new Array(rootNodes).fill('node-disconnect'),
382+
new Array(numberOfMasters).fill('node-disconnect'),
383383
);
384-
assert.deepStrictEqual(
384+
assert.deepEqual(
385385
log.slice(nodeDisconnect, disconnect),
386386
new Array(1).fill('disconnect'),
387387
);
388388

389-
assert.strictEqual(log.includes('error'), false);
390-
assert.strictEqual(log.includes('node-error'), false);
391-
assert.strictEqual(log.includes('node-reconnecting'), false);
389+
assert.equal(log.includes('error'), false);
390+
assert.equal(log.includes('node-error'), false);
391+
assert.equal(log.includes('node-reconnecting'), false);
392392

393393
}, {
394394
...GLOBAL.CLUSTERS.OPEN,
395-
disableClusterSetup: true
396-
} as any);
397-
395+
disableClusterSetup: true,
396+
});
398397
});
399398

400399
});

0 commit comments

Comments
 (0)