Skip to content

Commit

Permalink
fix: Update events that are propagated from pool cluster to include r…
Browse files Browse the repository at this point in the history
…emove (#2114)

* Add test for events being propegated through promise wrapper for pool cluster

* Propagate pool cluster remove event and don't propegate events that don't happen

* Move pool cluster promise test to builtin-runner

* Update PoolCluster.d.ts to match promise.d.ts for pool cluster events
  • Loading branch information
Michael03 authored Jul 13, 2023
1 parent af6b6dc commit 927d209
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface PoolCluster extends EventEmitter {

on(event: string, listener: (args: any[]) => void): this;
on(event: 'remove', listener: (nodeId: number) => void): this;
on(event: 'connection', listener: (connection: PoolConnection) => void): this;
on(event: 'warn', listener: (err: Error) => void): this;
}

export function createConnection(connectionUri: string): Promise<Connection>;
Expand Down
2 changes: 1 addition & 1 deletion promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class PromisePoolCluster extends EventEmitter {
super();
this.poolCluster = poolCluster;
this.Promise = thePromise || Promise;
inheritEvents(poolCluster, this, ['acquire', 'connection', 'enqueue', 'release']);
inheritEvents(poolCluster, this, ['warn', 'remove']);
}

getConnection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, it, before, after } from 'node:test';
import assert from 'node:assert';
import common from '../../../common.js';
import { createPoolCluster } from "../../../../promise.js"

describe('Test pool cluster', { timeout: 1000 }, () => {

it('should propagate warn event to promise wrapper', (t, done) => {

const poolCluster = createPoolCluster();
/* eslint-disable no-invalid-this */
poolCluster
.once('warn', function () {
assert.equal(this, poolCluster);
done();
})
/* eslint-enable no-invalid-this */
poolCluster.poolCluster.emit('warn', new Error());
});

it('should propagate remove event to promise wrapper', (t, done) => {

const poolCluster = createPoolCluster();
/* eslint-disable no-invalid-this */
poolCluster
.once('remove', function () {
assert.equal(this, poolCluster);
done();
});
/* eslint-enable no-invalid-this */
poolCluster.poolCluster.emit('remove');
});
});
2 changes: 1 addition & 1 deletion typings/mysql/lib/PoolCluster.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ declare class PoolCluster extends EventEmitter {

on(event: string, listener: (args: any[]) => void): this;
on(event: 'remove', listener: (nodeId: number) => void): this;
on(event: 'connection', listener: (connection: PoolConnection) => void): this;
on(event: 'warn', listener: (err: Error) => void): this;
}

export { PoolCluster };

0 comments on commit 927d209

Please # to comment.