import ava, { TestInterface } from 'ava'; import { SharedContext } from '@ava/cooperate'; import { context, lock } from './shared'; // const context2 = new SharedContext('my-context-2'); // const lock2 = context.createLock('my-lock-2'); 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 1:'); // await getDb(t); t.context.release = await lock.acquire(); // t.context.release2 = await lock2.acquire(); console.log('got lock 1:'); }); 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 1 over:'); // console.log(t.context.db.client); }); // // Constants // const userQuery = ` query User($id: ID) { user(id: $id) { id recipes { id } } } `; // // Tests // test('lock 1 test', async t => { // const db = t.context.db.client; // await db.user.create({ data: {} }); console.log('run test 1') await sleep(4000); t.pass(); }); async function sleep(time: number) { console.log(`sleep ${time}ms`); return new Promise((resolve) => { setTimeout(resolve, time); }) }