Skip to content

Commit 288e45d

Browse files
committed
Test that poolQueryViaFetch is inhibited by connect listener, and driver fix to ensure it is
1 parent 0da9b27 commit 288e45d

File tree

11 files changed

+206
-176
lines changed

11 files changed

+206
-176
lines changed

dist/dts/_extracted.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export declare class Pool extends Pool_2 {
444444
Client: typeof Client;
445445
hasFetchUnsupportedListeners: boolean;
446446
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
447+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
447448
query(config?: any, values?: any, cb?: any): any;
448449
}
449450

dist/dts/_extracted.d.ts.orig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export declare class Pool extends Pool_2 {
444444
Client: typeof Client;
445445
hasFetchUnsupportedListeners: boolean;
446446
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
447+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
447448
query(config?: any, values?: any, cb?: any): any;
448449
}
449450

dist/dts/export/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ declare class NeonPool extends Pool {
4343
Client: typeof NeonClient;
4444
hasFetchUnsupportedListeners: boolean;
4545
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
46+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
4647
query(config?: any, values?: any, cb?: any): any;
4748
}
4849
export { Socket as neonConfig, NeonPool as Pool, NeonClient as Client, neon, NeonDbError, };

dist/jsr/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
446446
Client: typeof Client;
447447
hasFetchUnsupportedListeners: boolean;
448448
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
449+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
449450
query(config?: any, values?: any, cb?: any): any;
450451
}
451452

dist/jsr/index.js

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

dist/npm/index.d.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
446446
Client: typeof Client;
447447
hasFetchUnsupportedListeners: boolean;
448448
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
449+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
449450
query(config?: any, values?: any, cb?: any): any;
450451
}
451452

dist/npm/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
446446
Client: typeof Client;
447447
hasFetchUnsupportedListeners: boolean;
448448
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
449+
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
449450
query(config?: any, values?: any, cb?: any): any;
450451
}
451452

dist/npm/index.js

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

dist/npm/index.mjs

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

export/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ class NeonPool extends Pool {
313313
return super.on(event as any, listener);
314314
}
315315

316+
addListener = this.on;
317+
316318
// @ts-ignore -- is it even possible to make TS happy with these overloaded function types?
317319
query(config?: any, values?: any, cb?: any) {
318320
if (

tests/ws.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test, beforeAll } from 'vitest';
1+
import { expect, test, beforeAll, vi } from 'vitest';
22
import { Pool as PgPool } from 'pg';
33
import * as subtls from 'subtls';
44
import { sampleQueries } from './sampleQueries';
@@ -78,7 +78,29 @@ test('pool.query() with poolQueryViaFetch', async () => {
7878
}
7979
});
8080

81-
// TODO: poolQueryViaFetch with contra-indications
81+
test('pool.query() with poolQueryViaFetch but also a listener that prevents fetch', async () => {
82+
neonConfig.poolQueryViaFetch = true;
83+
84+
// use a new Pool because we know it will have to connect a new client
85+
const customPool = new WsPool({ connectionString: DB_URL });
86+
87+
try {
88+
const fn = vi.fn();
89+
const connectListener = () => {
90+
customPool.removeListener('connect', connectListener);
91+
fn();
92+
};
93+
customPool.addListener('connect', connectListener);
94+
95+
const wsResult = await customPool.query('SELECT $1::int AS one', [1]);
96+
expect(wsResult.rows).toStrictEqual([{ one: 1 }]);
97+
expect(wsResult).not.toHaveProperty('viaNeonFetch');
98+
expect(fn).toHaveBeenCalledOnce();
99+
} finally {
100+
neonConfig.poolQueryViaFetch = false;
101+
customPool.end();
102+
}
103+
});
82104

83105
test('client.query()', async () => {
84106
const client = new WsClient(DB_URL);

0 commit comments

Comments
 (0)