Skip to content

test: make Postgres custom extension installation test reusable locally - #12538

Merged
OSA413 merged 1 commit into
typeorm:masterfrom
OSA413:make-postgres-test-reusable
May 23, 2026
Merged

OSA413 merged 1 commit into
typeorm:masterfrom
OSA413:make-postgres-test-reusable

Conversation

@OSA413

@OSA413 OSA413 commented May 23, 2026

Copy link
Copy Markdown
Collaborator

Description of change

I've faced an issue that after running the test suite, the extensions stay installed, this broke re-run of the test in the same file locally (the other test expects no extensions installed). This change clears the two extensions that are installed during the test.

In the other hand, this "bug" in the test may indicate, that the applicationName for Postgres doesn't do anything in terms of the installed extension (see the changed file fully to understand it).

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

🛡️ Security fixes: Do not submit security fixes as public PRs — the diff exposes the vulnerability. Use GitHub Security Advisories instead.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0)

Grey Divider


Remediation recommended

1. After hook null-deref 🐞 Bug ☼ Reliability
Description
The new teardown calls dataSources.map(...) unconditionally; if createTestingConnections(...)
fails and dataSources remains undefined, the after hook throws a TypeError and can mask the
original failure. Previously closeTestingConnections(dataSources) was safe with undefined inputs
due to internal guards.
Code

test/functional/driver/postgres/data-source-options.test.ts[R56-62]

Evidence
The teardown uses dataSources.map(...) directly, which will throw if dataSources is undefined;
meanwhile closeTestingConnections explicitly returns early on falsy inputs, showing the previous
teardown path was safe even when setup failed.

test/functional/driver/postgres/data-source-options.test.ts[45-64]
test/utils/test-utils.ts[489-504]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The new `after(async () => { ... })` teardown dereferences `dataSources` via `.map()` without a guard. If the `before` hook fails before assigning `dataSources`, the teardown throws and obscures the root cause.

### Issue Context
`closeTestingConnections` already safely handles `undefined` / empty arrays, but the new teardown now touches `dataSources` before calling it.

### Fix Focus Areas
- test/functional/driver/postgres/data-source-options.test.ts[56-64]

### Suggested fix
Wrap teardown in a defensive pattern:
- Use `(dataSources ?? [])` when iterating
- (Optionally) early-return if `!dataSources`
- Keep `closeTestingConnections` in a `finally` block (see related finding)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Advisory comments

2. Teardown not in finally 🐞 Bug ☼ Reliability
Description
If any DROP EXTENSION query rejects, the awaited Promise.all(...) throws and
closeTestingConnections(dataSources) will not run, leaving the DataSource(s) initialized for the
remainder of the test process. Other tests in this repo use try/finally in after hooks to
guarantee connections are closed even when cleanup fails.
Code

test/functional/driver/postgres/data-source-options.test.ts[R56-64]

Evidence
In the updated test, closeTestingConnections is executed only after await Promise.all(...)
completes successfully, so any rejection skips the close. The repo already demonstrates a
try/finally teardown pattern to avoid this exact control-flow problem.

test/functional/driver/postgres/data-source-options.test.ts[56-64]
test/functional/transaction/isolation-level/cockroachdb-isolation.test.ts[193-206]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `after` hook performs cleanup work and then closes connections, but it does not use `try/finally`. Any failure during cleanup prevents `closeTestingConnections` from executing.

### Issue Context
A common pattern in this test suite is to wrap teardown work with `try { ... } finally { await closeTestingConnections(...) }`.

### Fix Focus Areas
- test/functional/driver/postgres/data-source-options.test.ts[56-64]

### Suggested fix
Refactor to:
```ts
after(async () => {
 try {
   await Promise.all((dataSources ?? []).map(async (dataSource) => {
     await dataSource.query("DROP EXTENSION IF EXISTS tablefunc")
     await dataSource.query("DROP EXTENSION IF EXISTS xml2")
   }))
 } finally {
   await closeTestingConnections(dataSources)
 }
})
```
This guarantees connection teardown regardless of cleanup outcome.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Qodo Logo

@OSA413
OSA413 merged commit 90352ce into typeorm:master May 23, 2026
43 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants