Skip to content

Commit 927d209

Browse files
authored
fix: Update events that are propagated from pool cluster to include remove (#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
1 parent af6b6dc commit 927d209

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

promise.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export interface PoolCluster extends EventEmitter {
117117

118118
on(event: string, listener: (args: any[]) => void): this;
119119
on(event: 'remove', listener: (nodeId: number) => void): this;
120-
on(event: 'connection', listener: (connection: PoolConnection) => void): this;
120+
on(event: 'warn', listener: (err: Error) => void): this;
121121
}
122122

123123
export function createConnection(connectionUri: string): Promise<Connection>;

promise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class PromisePoolCluster extends EventEmitter {
448448
super();
449449
this.poolCluster = poolCluster;
450450
this.Promise = thePromise || Promise;
451-
inheritEvents(poolCluster, this, ['acquire', 'connection', 'enqueue', 'release']);
451+
inheritEvents(poolCluster, this, ['warn', 'remove']);
452452
}
453453

454454
getConnection() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, it, before, after } from 'node:test';
2+
import assert from 'node:assert';
3+
import common from '../../../common.js';
4+
import { createPoolCluster } from "../../../../promise.js"
5+
6+
describe('Test pool cluster', { timeout: 1000 }, () => {
7+
8+
it('should propagate warn event to promise wrapper', (t, done) => {
9+
10+
const poolCluster = createPoolCluster();
11+
/* eslint-disable no-invalid-this */
12+
poolCluster
13+
.once('warn', function () {
14+
assert.equal(this, poolCluster);
15+
done();
16+
})
17+
/* eslint-enable no-invalid-this */
18+
poolCluster.poolCluster.emit('warn', new Error());
19+
});
20+
21+
it('should propagate remove event to promise wrapper', (t, done) => {
22+
23+
const poolCluster = createPoolCluster();
24+
/* eslint-disable no-invalid-this */
25+
poolCluster
26+
.once('remove', function () {
27+
assert.equal(this, poolCluster);
28+
done();
29+
});
30+
/* eslint-enable no-invalid-this */
31+
poolCluster.poolCluster.emit('remove');
32+
});
33+
});

typings/mysql/lib/PoolCluster.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ declare class PoolCluster extends EventEmitter {
8080

8181
on(event: string, listener: (args: any[]) => void): this;
8282
on(event: 'remove', listener: (nodeId: number) => void): this;
83-
on(event: 'connection', listener: (connection: PoolConnection) => void): this;
83+
on(event: 'warn', listener: (err: Error) => void): this;
8484
}
8585

8686
export { PoolCluster };

0 commit comments

Comments
 (0)