Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for #7864 #8997

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified test/bun.lockb
Binary file not shown.
Binary file modified test/js/third_party/prisma/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions test/js/third_party/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"typescript": "5.0.0"
},
"dependencies": {
"@napi-rs/canvas": "0.1.47",
"@prisma/client": "5.1.1"
}
}
59 changes: 50 additions & 9 deletions test/js/third_party/prisma/prisma.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @known-failing-on-windows: 1 failing

import { test as bunTest, expect, describe } from "bun:test";
import { generateClient } from "./helper.ts";
import type { PrismaClient } from "./prisma/types.d.ts";
import { createCanvas } from "@napi-rs/canvas";

function* TestIDGenerator(): Generator<number> {
while (true) {
Expand Down Expand Up @@ -49,6 +51,31 @@ async function cleanTestId(prisma: PrismaClient, testId: number) {
}

describe(`prisma ${type}`, () => {
if (type === "postgres") {
// https://github.com/oven-sh/bun/issues/7864
test("memory issue reproduction issue #7864", async (client, testId) => {
async function causeError() {
// 1. Some DB query
const tx = client.$executeRaw`SELECT pg_sleep(0.001)`;
// 2. Some napi-based operation
createCanvas(10, 10);
// 3. Wait for the DB query to finish
await tx;
}

for (let i = 0; i < 20; i++) {
try {
await causeError();
} catch (e) {
console.log(`Encountered error after ${i + 1} iterations`);
throw e;
}
}

expect().pass();
});
}

test(
"CRUD basics",
async (prisma: PrismaClient, testId: number) => {
Expand Down Expand Up @@ -139,25 +166,39 @@ async function cleanTestId(prisma: PrismaClient, testId: number) {
test(
"Should execute multiple commands at the same time",
async (prisma: PrismaClient, testId: number) => {
const users = await Promise.all(
function user(i: number) {
return {
testId,
name: `Test${i}`,
email: `test${i}@oven.sh`,
};
}
const createdUsers = await Promise.all(
new Array(10).fill(0).map((_, i) =>
prisma.user.create({
data: {
testId,
name: `Test${i}`,
email: `test${i}@oven.sh`,
},
data: user(i),
}),
),
);
expect(createdUsers.length).toBe(10);

expect(users.length).toBe(10);

users.forEach((user, i) => {
createdUsers.forEach((user, i) => {
expect(user?.name).toBe(`Test${i}`);
expect(user?.email).toBe(`test${i}@oven.sh`);
});

createdUsers.sort((a, b) => a.id - b.id);

for (let i = 0; i < 10; i++) {
const loadAllUsers10Times = await Promise.all(
new Array(10).fill(0).map(() => prisma.user.findMany({ where: { testId } })),
);
for (const users of loadAllUsers10Times) {
expect(users).toEqual(createdUsers);
}
Bun.gc(true);
}

const deletedUser = await prisma.user.deleteMany({ where: { testId } });

expect(deletedUser?.count).toBe(10);
Expand Down
7 changes: 4 additions & 3 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@grpc/grpc-js": "1.9.9",
"@grpc/proto-loader": "0.7.10",
"@napi-rs/canvas": "0.1.47",
"@prisma/client": "5.8.0",
"@resvg/resvg-js": "2.4.1",
"@swc/core": "1.3.38",
Expand All @@ -31,26 +32,26 @@
"mysql2": "3.7.0",
"node-gyp": "10.0.1",
"nodemailer": "6.9.3",
"pg": "8.11.1",
"pg-connection-string": "2.6.1",
"pg": "8.11.1",
"postgres": "3.3.5",
"prisma": "5.1.1",
"prompts": "2.4.2",
"reflect-metadata": "0.1.13",
"rollup": "4.4.1",
"sharp": "0.33.0",
"sinon": "6.0.0",
"socket.io": "4.7.1",
"socket.io-client": "4.7.1",
"socket.io": "4.7.1",
"string-width": "7.0.0",
"supertest": "6.3.3",
"svelte": "3.55.1",
"typescript": "5.0.2",
"undici": "5.20.0",
"verdaccio": "5.27.0",
"vitest": "0.32.2",
"webpack": "5.88.0",
"webpack-cli": "4.7.2",
"webpack": "5.88.0",
"yargs": "17.7.2"
},
"private": true,
Expand Down
Loading