adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.02k stars 189 forks source link

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

Open craigharman opened 6 days ago

craigharman commented 6 days ago

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:

volumes: postgres_volume:

`docker compose up`

3. Add the database credentials above to .env

4. In `tests/bootstrap.ts`:

export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = { setup: [() => testUtils.db().truncate()], teardown: [], }

5. 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) }) })

6. 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) } }

7. `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 commented 2 days ago

Hey @craigharman! 👋🏻

A few questions here:

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