mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
test(server): avoid db deadlock on unittest (#10104)
https://github.com/toeverything/AFFiNE/runs/37010719190 
This commit is contained in:
@@ -5,7 +5,7 @@ import { EmailAlreadyUsed, EventBus } from '../../base';
|
|||||||
import { WorkspaceRole } from '../../core/permission';
|
import { WorkspaceRole } from '../../core/permission';
|
||||||
import { UserModel } from '../../models/user';
|
import { UserModel } from '../../models/user';
|
||||||
import { WorkspaceMemberStatus } from '../../models/workspace';
|
import { WorkspaceMemberStatus } from '../../models/workspace';
|
||||||
import { createTestingModule, type TestingModule } from '../utils';
|
import { createTestingModule, sleep, type TestingModule } from '../utils';
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
module: TestingModule;
|
module: TestingModule;
|
||||||
@@ -272,6 +272,9 @@ test('should trigger user.deleted event', async t => {
|
|||||||
t.true(
|
t.true(
|
||||||
spy.calledOnceWithExactly({ ...user, ownedWorkspaces: ['test-workspace'] })
|
spy.calledOnceWithExactly({ ...user, ownedWorkspaces: ['test-workspace'] })
|
||||||
);
|
);
|
||||||
|
// await for 'user.deleted' event to be emitted and executed
|
||||||
|
// avoid race condition cause database dead lock
|
||||||
|
await sleep(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should paginate users', async t => {
|
test('should paginate users', async t => {
|
||||||
|
|||||||
@@ -156,8 +156,15 @@ export class TestingApp extends ApplyType<INestApplication>() {
|
|||||||
.send({
|
.send({
|
||||||
query,
|
query,
|
||||||
variables,
|
variables,
|
||||||
})
|
});
|
||||||
.expect(200);
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to execute gql: ${query}, status: ${res.status}, body: ${JSON.stringify(
|
||||||
|
res.body
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (res.body.errors?.length) {
|
if (res.body.errors?.length) {
|
||||||
throw new Error(res.body.errors[0].message);
|
throw new Error(res.body.errors[0].message);
|
||||||
|
|||||||
Reference in New Issue
Block a user