mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Mark other PGlite test as TODO on Linux x64 (#18201)
This commit is contained in:
138
test/js/third_party/pg-gateway/pglite.test.ts
vendored
138
test/js/third_party/pg-gateway/pglite.test.ts
vendored
@@ -4,16 +4,23 @@ import net, { AddressInfo } from "node:net";
|
||||
import { fromNodeSocket } from "pg-gateway/node";
|
||||
import { expect, test } from "bun:test";
|
||||
import { once } from "events";
|
||||
test("pglite should be able to query using pg-gateway and Bun.SQL", async () => {
|
||||
const name = "test_" + randomUUIDv7("hex").replaceAll("-", "");
|
||||
const dataDir = `memory://${name}`;
|
||||
const db = new PGlite(dataDir);
|
||||
import { isCI, isLinux } from "harness";
|
||||
|
||||
// Wait for the database to initialize
|
||||
await db.waitReady;
|
||||
// TODO(@190n) linux-x64 sometimes fails due to JavaScriptCore bug
|
||||
// https://github.com/oven-sh/bun/issues/17841#issuecomment-2695792567
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=289009
|
||||
test.todoIf(isCI && isLinux && process.arch == "x64")(
|
||||
"pglite should be able to query using pg-gateway and Bun.SQL",
|
||||
async () => {
|
||||
const name = "test_" + randomUUIDv7("hex").replaceAll("-", "");
|
||||
const dataDir = `memory://${name}`;
|
||||
const db = new PGlite(dataDir);
|
||||
|
||||
// Create a simple test table
|
||||
await db.exec(`
|
||||
// Wait for the database to initialize
|
||||
await db.waitReady;
|
||||
|
||||
// Create a simple test table
|
||||
await db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS test_table (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL
|
||||
@@ -22,69 +29,70 @@ test("pglite should be able to query using pg-gateway and Bun.SQL", async () =>
|
||||
INSERT INTO test_table (name) VALUES ('Test 1'), ('Test 2'), ('Test 3');
|
||||
`);
|
||||
|
||||
// Create a simple server using pg-gateway
|
||||
const server = net.createServer(async socket => {
|
||||
await fromNodeSocket(socket, {
|
||||
serverVersion: "16.3",
|
||||
auth: {
|
||||
method: "trust",
|
||||
},
|
||||
async onStartup() {
|
||||
// Wait for PGlite to be ready before further processing
|
||||
await db.waitReady;
|
||||
},
|
||||
async onMessage(data, { isAuthenticated }: { isAuthenticated: boolean }) {
|
||||
// Only forward messages to PGlite after authentication
|
||||
if (!isAuthenticated) {
|
||||
return;
|
||||
}
|
||||
// Create a simple server using pg-gateway
|
||||
const server = net.createServer(async socket => {
|
||||
await fromNodeSocket(socket, {
|
||||
serverVersion: "16.3",
|
||||
auth: {
|
||||
method: "trust",
|
||||
},
|
||||
async onStartup() {
|
||||
// Wait for PGlite to be ready before further processing
|
||||
await db.waitReady;
|
||||
},
|
||||
async onMessage(data, { isAuthenticated }: { isAuthenticated: boolean }) {
|
||||
// Only forward messages to PGlite after authentication
|
||||
if (!isAuthenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
return await db.execProtocolRaw(data);
|
||||
},
|
||||
return await db.execProtocolRaw(data);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Start listening
|
||||
await once(server.listen(0), "listening");
|
||||
// Start listening
|
||||
await once(server.listen(0), "listening");
|
||||
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
const port = (server.address() as AddressInfo).port;
|
||||
|
||||
await using sql = new SQL({
|
||||
hostname: "localhost",
|
||||
port: port,
|
||||
database: name,
|
||||
max: 1,
|
||||
});
|
||||
await using sql = new SQL({
|
||||
hostname: "localhost",
|
||||
port: port,
|
||||
database: name,
|
||||
max: 1,
|
||||
});
|
||||
|
||||
{
|
||||
// prepared statement without parameters
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = 1`;
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
{
|
||||
// prepared statement without parameters
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = 1`;
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
|
||||
{
|
||||
// using prepared statement
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = ${1}`;
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
{
|
||||
// using prepared statement
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = ${1}`;
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
|
||||
{
|
||||
// using simple query
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = 1`.simple();
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
{
|
||||
// using simple query
|
||||
const result = await sql`SELECT * FROM test_table WHERE id = 1`.simple();
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
|
||||
{
|
||||
// using unsafe with parameters
|
||||
const result = await sql.unsafe("SELECT * FROM test_table WHERE id = $1", [1]);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
});
|
||||
{
|
||||
// using unsafe with parameters
|
||||
const result = await sql.unsafe("SELECT * FROM test_table WHERE id = $1", [1]);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toEqual({ id: 1, name: "Test 1" });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user