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

When running tests i get [ error ] Migration completed, but unable to release database lock #1040

Open
craigharman opened this issue Jun 22, 2024 · 2 comments

Comments

@craigharman
Copy link

Package version

6.9.0

Describe the bug

Apologies if this issue would be better in vine or lucid repos, but it seems to touch on all through pacakges, so thought it best to report here.

Everytime I run a very basic test with npm run test I get the error:

[ error ] Migration completed, but unable to release database lock

This then causes the test results to hang and not quit which is painful when running individual tests within VSCode.

I have looked on discord and found a number of people having a similar issue:

https://discord.com/channels/423256550564691970/1246405673772646432
https://discord.com/channels/423256550564691970/1113490995892457573
https://discord.com/channels/423256550564691970/423256550564691972/1087399322506768497

I have created some steps to recreate:

  1. Install a new adonisjs project (with Lucid and webstarter kit)
  2. create docker-compose.yml with following content:
version: '3.8'

services:
  st_postgres:
    container_name: test_postgres
    image: postgres:13
    volumes:
      - postgres_volume:/var/lib/postgresql/data
      - ./docker/postgres-dev-init.sql:/docker-entrypoint-initdb.d/init.sql # will setup dev database adonis_app for us
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - 5432:5432

volumes:
  postgres_volume:

docker compose up

  1. Add the database credentials above to .env

  2. In tests/bootstrap.ts:

export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
  setup: [() => testUtils.db().truncate()],
  teardown: [],
}
  1. Create a unit test in /tests/unit/test.spec.ts it can do anything:
import { test } from '@japa/runner'

test.group('A test just so something executes', (group) => {
  test('Test that something happens', async ({ assert }) => {
    assert.equal(true, true)
  })
})
  1. Add a migration file (again it can be anything):
import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
  protected tableName = 'tests'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')

      table.timestamp('created_at')
      table.timestamp('updated_at')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
  1. npm run test

Every time I execute this I get the error:

[ error ] Migration completed, but unable to release database lock

If you remove the testUtils.db().truncate() from the setup command in bootstrap, the test runs fine.

Reproduction repo

No response

@RomainLanz RomainLanz transferred this issue from adonisjs/core Jun 25, 2024
@RomainLanz
Copy link
Member

Hey @craigharman! 👋🏻

A few questions here:

  • Is there any reason to use PSQL 13 instead of the latest release?
  • Could you share the SQL script that set up the database?

In fact, the best would be to have a repository with the code you use to reproduce the issue.

@craigharman
Copy link
Author

It was just what I was using, but have since upgraded to postgres:latest and still have the same issue.
I'll put a repo together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants