Skip to content

Commit

Permalink
Test that poolQueryViaFetch is inhibited by connect listener, and dri…
Browse files Browse the repository at this point in the history
…ver fix to ensure it is
  • Loading branch information
jawj committed Dec 19, 2024
1 parent 0da9b27 commit 288e45d
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 176 deletions.
1 change: 1 addition & 0 deletions dist/dts/_extracted.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}

Expand Down
1 change: 1 addition & 0 deletions dist/dts/_extracted.d.ts.orig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}

Expand Down
1 change: 1 addition & 0 deletions dist/dts/export/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare class NeonPool extends Pool {
Client: typeof NeonClient;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}
export { Socket as neonConfig, NeonPool as Pool, NeonClient as Client, neon, NeonDbError, };
Expand Down
1 change: 1 addition & 0 deletions dist/jsr/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}

Expand Down
116 changes: 58 additions & 58 deletions dist/jsr/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/npm/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}

Expand Down
1 change: 1 addition & 0 deletions dist/npm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export declare class Pool extends Pool_2 {
Client: typeof Client;
hasFetchUnsupportedListeners: boolean;
on(event: 'error' | 'connect' | 'acquire' | 'release' | 'remove', listener: any): this;
addListener: (event: "error" | "connect" | "acquire" | "release" | "remove", listener: any) => this;
query(config?: any, values?: any, cb?: any): any;
}

Expand Down
116 changes: 58 additions & 58 deletions dist/npm/index.js

Large diffs are not rendered by default.

116 changes: 58 additions & 58 deletions dist/npm/index.mjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class NeonPool extends Pool {
return super.on(event as any, listener);
}

addListener = this.on;

// @ts-ignore -- is it even possible to make TS happy with these overloaded function types?
query(config?: any, values?: any, cb?: any) {
if (
Expand Down
26 changes: 24 additions & 2 deletions tests/ws.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, beforeAll } from 'vitest';
import { expect, test, beforeAll, vi } from 'vitest';
import { Pool as PgPool } from 'pg';
import * as subtls from 'subtls';
import { sampleQueries } from './sampleQueries';
Expand Down Expand Up @@ -78,7 +78,29 @@ test('pool.query() with poolQueryViaFetch', async () => {
}
});

// TODO: poolQueryViaFetch with contra-indications
test('pool.query() with poolQueryViaFetch but also a listener that prevents fetch', async () => {
neonConfig.poolQueryViaFetch = true;

// use a new Pool because we know it will have to connect a new client
const customPool = new WsPool({ connectionString: DB_URL });

try {
const fn = vi.fn();
const connectListener = () => {
customPool.removeListener('connect', connectListener);
fn();
};
customPool.addListener('connect', connectListener);

const wsResult = await customPool.query('SELECT $1::int AS one', [1]);
expect(wsResult.rows).toStrictEqual([{ one: 1 }]);
expect(wsResult).not.toHaveProperty('viaNeonFetch');
expect(fn).toHaveBeenCalledOnce();
} finally {
neonConfig.poolQueryViaFetch = false;
customPool.end();
}
});

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

0 comments on commit 288e45d

Please sign in to comment.