import ava, { TestInterface } from 'ava'; import { SharedContext } from '@ava/cooperate'; import { lock } from './shared'; // const context = new SharedContext('my-context'); // const lock = context.createLock('my-lock'); import type { DBTestContext } from '../utils/get-db'; import { getDb } from '../utils/test-worker'; // Setup // const test = ava as TestInterface; test.before(async t => { console.log('before test 2:'); t.context.release = await lock.acquire(); console.log('got lock 2:'); }); test.afterEach.always(async t => { // await testUtils.cleanupDB(t); }); test.after.always(async t => { // await t.context.db.teardown(); // t.context.release(); console.log('test 2 over:'); // console.log(t.context.db.client); }); // // Constants // const userQuery = ` query User($id: ID) { user(id: $id) { id recipes { id } } } `; // // Tests // test('lock 2 test', async t => { // const db = t.context.db.client; // await db.user.create({ data: {} }); console.log('run test 2') await sleep(4000); t.pass(); }); async function sleep(time: number) { console.log(`sleep ${time}ms`); return new Promise((resolve) => { setTimeout(resolve, time); }) }