Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 8db2dae

Browse files
committed
Update Neon config, fix bash
1 parent 50d24f0 commit 8db2dae

File tree

5 files changed

+57
-61
lines changed

5 files changed

+57
-61
lines changed

.github/workflows/release-feature-branch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ jobs:
179179
--exclude tests/pg/neon-serverless.test.ts
180180
;;
181181
182+
esac
183+
182184
183185
attw:
184186
# only run on all pushes or pull requests from forks

integration-tests/docker-neon.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
postgres:
3+
image: 'postgres:latest'
4+
environment:
5+
POSTGRES_USER: postgres
6+
POSTGRES_PASSWORD: postgres
7+
POSTGRES_DB: postgres
8+
ports:
9+
- '5432:5441'
10+
healthcheck:
11+
test: ['CMD-SHELL', 'pg_isready -U postgres']
12+
interval: 10s
13+
timeout: 5s
14+
retries: 5
15+
neon-proxy:
16+
image: ghcr.io/timowilhelm/local-neon-http-proxy:main
17+
environment:
18+
- PG_CONNECTION_STRING=postgres://postgres:postgres@postgres:5432/postgres
19+
ports:
20+
- '4444:4444'
21+
depends_on:
22+
postgres:
23+
condition: service_healthy
24+
pg_proxy:
25+
image: ghcr.io/neondatabase/wsproxy:latest
26+
environment:
27+
APPEND_PORT: 'postgres:5432'
28+
ALLOW_ADDR_REGEX: '.*'
29+
LOG_TRAFFIC: 'true'
30+
ports:
31+
- '5446:80'
32+
depends_on:
33+
- postgres

integration-tests/tests/pg/neon-http.test.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
1-
import { neon, type NeonQueryFunction } from '@neondatabase/serverless';
2-
import retry from 'async-retry';
1+
import { neon, neonConfig, type NeonQueryFunction } from '@neondatabase/serverless';
32
import { eq, sql } from 'drizzle-orm';
43
import { drizzle, type NeonHttpDatabase } from 'drizzle-orm/neon-http';
54
import { migrate } from 'drizzle-orm/neon-http/migrator';
65
import { pgMaterializedView, pgTable, serial, timestamp } from 'drizzle-orm/pg-core';
7-
import { Client } from 'pg';
8-
import { afterAll, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
6+
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
97
import { skipTests } from '~/common';
108
import { randomString } from '~/utils';
119
import { tests, usersMigratorTable, usersTable } from './pg-common';
1210

1311
const ENABLE_LOGGING = false;
1412

1513
let db: NeonHttpDatabase;
16-
let ddlRunner: Client;
17-
let client: NeonQueryFunction<any, any>;
1814

1915
beforeAll(async () => {
2016
const connectionString = process.env['NEON_CONNECTION_STRING'];
2117
if (!connectionString) {
2218
throw new Error('NEON_CONNECTION_STRING is not defined');
2319
}
24-
client = neon(connectionString);
25-
ddlRunner = await retry(async () => {
26-
ddlRunner = new Client(connectionString);
27-
await ddlRunner.connect();
28-
return ddlRunner;
29-
}, {
30-
retries: 20,
31-
factor: 1,
32-
minTimeout: 250,
33-
maxTimeout: 250,
34-
randomize: false,
35-
onRetry() {
36-
ddlRunner?.end();
37-
},
38-
});
39-
db = drizzle(client, { logger: ENABLE_LOGGING });
40-
});
4120

42-
afterAll(async () => {
43-
await ddlRunner?.end();
21+
neonConfig.fetchEndpoint = (host) => {
22+
const [protocol, port] = host === 'db.localtest.me' ? ['http', 4444] : ['https', 443];
23+
return `${protocol}://${host}:${port}/sql`;
24+
};
25+
neonConfig.poolQueryViaFetch = true;
26+
db = drizzle(neon(connectionString), { logger: ENABLE_LOGGING });
4427
});
4528

4629
beforeEach((ctx) => {

integration-tests/tests/pg/neon-serverless.test.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { neonConfig, Pool } from '@neondatabase/serverless';
2-
import retry from 'async-retry';
32
import { eq, sql } from 'drizzle-orm';
43
import { drizzle, type NeonDatabase } from 'drizzle-orm/neon-serverless';
54
import { migrate } from 'drizzle-orm/neon-serverless/migrator';
@@ -15,31 +14,19 @@ const ENABLE_LOGGING = false;
1514
let db: NeonDatabase;
1615
let client: Pool;
1716

17+
// neonConfig.wsProxy = (host) => `${host}:5446/v1`;
18+
// neonConfig.useSecureWebSocket = false;
19+
// neonConfig.pipelineTLS = false;
20+
// neonConfig.pipelineConnect = false;
21+
// neonConfig.webSocketConstructor = ws;
22+
1823
beforeAll(async () => {
19-
const connectionString = process.env['NEON_CONNECTION_STRING'];
24+
const connectionString = process.env['NEON_SERVERLESS_CONNECTION_STRING'] ?? process.env['NEON_CONNECTION_STRING'];
2025
if (!connectionString) {
21-
throw new Error('NEON_CONNECTION_STRING is not defined');
26+
throw new Error('Neither NEON_SERVERLESS_CONNECTION_STRING nor NEON_CONNECTION_STRING are defined');
2227
}
2328

24-
neonConfig.webSocketConstructor = ws;
25-
26-
client = await retry(async () => {
27-
client = new Pool({ connectionString });
28-
29-
const cnt = await client.connect();
30-
cnt.release();
31-
32-
return client;
33-
}, {
34-
retries: 20,
35-
factor: 1,
36-
minTimeout: 250,
37-
maxTimeout: 250,
38-
randomize: false,
39-
onRetry() {
40-
client?.end();
41-
},
42-
});
29+
client = new Pool({ connectionString });
4330
db = drizzle(client, { logger: ENABLE_LOGGING });
4431
});
4532

integration-tests/tests/pg/pg-common.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ export function tests() {
541541
const result = await db.select().from(usersTable);
542542

543543
expect(result[0]!.createdAt).toBeInstanceOf(Date);
544-
expect(Math.abs(result[0]!.createdAt.getTime() - now)).toBeLessThan(100);
544+
expect(Math.abs(result[0]!.createdAt.getTime() - now)).toBeLessThan(300);
545545
expect(result).toEqual([{ id: 1, name: 'John', verified: false, jsonb: null, createdAt: result[0]!.createdAt }]);
546546
});
547547

@@ -734,7 +734,7 @@ export function tests() {
734734
.returning();
735735

736736
expect(users[0]!.createdAt).toBeInstanceOf(Date);
737-
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(100);
737+
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(300);
738738
expect(users).toEqual([
739739
{ id: 1, name: 'Jane', verified: false, jsonb: null, createdAt: users[0]!.createdAt },
740740
]);
@@ -765,7 +765,7 @@ export function tests() {
765765
const users = await db.delete(usersTable).where(eq(usersTable.name, 'John')).returning();
766766

767767
expect(users[0]!.createdAt).toBeInstanceOf(Date);
768-
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(100);
768+
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(300);
769769
expect(users).toEqual([
770770
{ id: 1, name: 'John', verified: false, jsonb: null, createdAt: users[0]!.createdAt },
771771
]);
@@ -4086,7 +4086,7 @@ export function tests() {
40864086
const result = await db.select().from(usersMySchemaTable);
40874087

40884088
expect(result[0]!.createdAt).toBeInstanceOf(Date);
4089-
expect(Math.abs(result[0]!.createdAt.getTime() - now)).toBeLessThan(100);
4089+
expect(Math.abs(result[0]!.createdAt.getTime() - now)).toBeLessThan(300);
40904090
expect(result).toEqual([{ id: 1, name: 'John', verified: false, jsonb: null, createdAt: result[0]!.createdAt }]);
40914091
});
40924092

@@ -4196,7 +4196,7 @@ export function tests() {
41964196
const users = await db.delete(usersMySchemaTable).where(eq(usersMySchemaTable.name, 'John')).returning();
41974197

41984198
expect(users[0]!.createdAt).toBeInstanceOf(Date);
4199-
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(100);
4199+
expect(Math.abs(users[0]!.createdAt.getTime() - now)).toBeLessThan(300);
42004200
expect(users).toEqual([{ id: 1, name: 'John', verified: false, jsonb: null, createdAt: users[0]!.createdAt }]);
42014201
});
42024202

@@ -4227,15 +4227,6 @@ export function tests() {
42274227
test('mySchema :: insert many', async (ctx) => {
42284228
const { db } = ctx.pg;
42294229

4230-
console.log('before');
4231-
console.log(
4232-
db.insert(usersMySchemaTable).values([
4233-
{ name: 'John' },
4234-
{ name: 'Bruce', jsonb: ['foo', 'bar'] },
4235-
{ name: 'Jane' },
4236-
{ name: 'Austin', verified: true },
4237-
]).toSQL(),
4238-
);
42394230
await db.insert(usersMySchemaTable).values([
42404231
{ name: 'John' },
42414232
{ name: 'Bruce', jsonb: ['foo', 'bar'] },

0 commit comments

Comments
 (0)