mirror of
https://github.com/immich-app/immich.git
synced 2025-04-08 03:01:32 -05:00
test: fix flaky user handle delete check medium test (#17253)
we can't run specifically the handleUserDeleteCheck tests concurrently due to one of the tests modifying the config in the shared database if run concurrently you can get race conditions where the other tests pick up the change, even with resetting the config in the beforeEach therefore the test that checks a delete actually happens, fails there are many ways to solve this, disabling concurrency for the suite, forcing sequential tests for just handleUserDeleteCheck, increasing the delete test deletedAt to more than the custom duration tests deleteDelay I applied all three of these. You could also force all the user tests to run in their own databases, but that feels overkill
This commit is contained in:
parent
a831876fdc
commit
d613f15606
1 changed files with 16 additions and 7 deletions
|
@ -13,7 +13,7 @@ const setup = async (db: Kysely<DB>) => {
|
|||
return { sut, mocks, context };
|
||||
};
|
||||
|
||||
describe.concurrent(UserService.name, () => {
|
||||
describe(UserService.name, () => {
|
||||
let sut: UserService;
|
||||
let context: TestContext;
|
||||
let mocks: ServiceMocks;
|
||||
|
@ -124,22 +124,31 @@ describe.concurrent(UserService.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('handleUserDeleteCheck', () => {
|
||||
describe.sequential('handleUserDeleteCheck', () => {
|
||||
beforeEach(async () => {
|
||||
// These tests specifically have to be sequential otherwise we hit race conditions with config changes applying in incorrect tests
|
||||
const config = await sut.getConfig({ withCache: false });
|
||||
config.user.deleteDelay = 7;
|
||||
await sut.updateConfig(config);
|
||||
});
|
||||
|
||||
it('should work when there are no deleted users', async () => {
|
||||
await expect(sut.handleUserDeleteCheck()).resolves.toEqual(JobStatus.SUCCESS);
|
||||
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledExactlyOnceWith([]);
|
||||
});
|
||||
|
||||
it('should work when there is a user to delete', async () => {
|
||||
const { sut, context, mocks } = await setup(await getKyselyDB());
|
||||
const user = TestFactory.user({ deletedAt: DateTime.now().minus({ days: 25 }).toJSDate() });
|
||||
const user = TestFactory.user({ deletedAt: DateTime.now().minus({ days: 60 }).toJSDate() });
|
||||
|
||||
await context.createUser(user);
|
||||
|
||||
await expect(sut.handleUserDeleteCheck()).resolves.toEqual(JobStatus.SUCCESS);
|
||||
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([{ name: JobName.USER_DELETION, data: { id: user.id } }]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledExactlyOnceWith([
|
||||
{ name: JobName.USER_DELETION, data: { id: user.id } },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should skip a recently deleted user', async () => {
|
||||
|
@ -150,7 +159,7 @@ describe.concurrent(UserService.name, () => {
|
|||
|
||||
await expect(sut.handleUserDeleteCheck()).resolves.toEqual(JobStatus.SUCCESS);
|
||||
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledExactlyOnceWith([]);
|
||||
});
|
||||
|
||||
it('should respect a custom user delete delay', async () => {
|
||||
|
@ -166,7 +175,7 @@ describe.concurrent(UserService.name, () => {
|
|||
|
||||
await expect(sut.handleUserDeleteCheck()).resolves.toEqual(JobStatus.SUCCESS);
|
||||
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledExactlyOnceWith([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue