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

afterAll callback not called when using preload script #4035

Closed
IlyaSemenov opened this issue Aug 7, 2023 · 3 comments
Closed

afterAll callback not called when using preload script #4035

IlyaSemenov opened this issue Aug 7, 2023 · 3 comments
Labels
bug Something isn't working bun:test Something related to the `bun test` runner

Comments

@IlyaSemenov
Copy link

What version of Bun is running?

0.7.2

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

bun add orchid-orm pqm
createdb test

Test file foo.test.ts:

import { test } from "bun:test"

import { db } from "./setup"

test("test", async () => {
	await db.$query`select 1`
})

Preload file setup.ts:

import { afterAll, beforeAll } from "bun:test"
import { orchidORM, testTransaction } from "orchid-orm"

export const db = orchidORM({ databaseURL: "postgres://user@localhost/test", log: true }, {})

beforeAll(async () => {
	console.log("before all")
	await testTransaction.start(db)
})

afterAll(async () => {
	console.log("after all")
	await testTransaction.close(db)
})

Run it with: bun test -r ./setup.ts foo.test.ts

What is the expected behavior?

The test passes. afterAll is called and at least prints to console.

What do you see instead?

afterAll is never called, the test runner hangs (probably due to open pg pool with active transaction):

bun test v0.7.2 (9574db35)

foo.test.ts:
before all
(9.8ms) BEGIN
(0.5ms) select 1
✓ test [0.74ms]
<--- here it hangs forever

Additional information

Everything works if the test and beforeAll/afterAll are in the single file foo.test.ts:

import { afterAll, beforeAll, test } from "bun:test"
import { orchidORM, testTransaction } from "orchid-orm"

const db = orchidORM({ databaseURL: "postgres://user@localhost/test", log: true }, {})

beforeAll(async () => {
	console.log("before all")
	await testTransaction.start(db)
})

afterAll(async () => {
	console.log("after all")
	await testTransaction.close(db)
})

test("test", async () => {
	await db.$query`select 1`
})
bun test v0.7.2 (9574db35)

foo.test.ts:
before all
(22.5ms) BEGIN
(1.5ms) select 1
✓ test [1.72ms]
after all
(3.9ms) ROLLBACK

 1 pass
 0 fail
Ran 1 tests across 1 files. [89.00ms]
@IlyaSemenov IlyaSemenov added the bug Something isn't working label Aug 7, 2023
@Electroid Electroid added the bun:test Something related to the `bun test` runner label Aug 7, 2023
@Th1nkK1D
Copy link

Found the same issue here on Bun 1.0.11 with both postgres.js and pg. Likely it has something to do with the Postgres connection that is still alive. A similar issue and workaround were reported to porsager/postgres#682

@masterT
Copy link

masterT commented Nov 21, 2023

This seems fixed with Bun 1.0.13.

@Th1nkK1D
Copy link

This seems fixed with Bun 1.0.13.

Confirmed. Upgraded to 1.0.13 and the issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:test Something related to the `bun test` runner
Projects
None yet
Development

No branches or pull requests

5 participants