Skip to content

Commit c81fe37

Browse files
committed
test(grouper): remove duplicate-key race regression case
1 parent 44c93a7 commit c81fe37

1 file changed

Lines changed: 1 addition & 42 deletions

File tree

workers/grouper/tests/index.test.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { RedisClientType } from 'redis';
55
import { createClient } from 'redis';
66
import type { Collection } from 'mongodb';
77
import { MongoClient } from 'mongodb';
8-
import type { ErrorsCatcherType, EventAddons, EventData, GroupedEventDBScheme } from '@hawk.so/types';
8+
import type { ErrorsCatcherType, EventAddons, EventData } from '@hawk.so/types';
99
import { MS_IN_SEC } from '../../../lib/utils/consts';
1010
import TimeMs from '../../../lib/utils/time';
1111
import * as mongodb from 'mongodb';
@@ -173,47 +173,6 @@ describe('GrouperWorker', () => {
173173
expect(await eventsCollection.find().count()).toBe(1);
174174
});
175175

176-
test('Should process event as repetition after duplicate key race', async () => {
177-
const duplicateKeyErrorCode = 11000;
178-
const task = generateTask();
179-
const workerWithSaveEvent = worker as unknown as {
180-
saveEvent: (
181-
projectId: string,
182-
groupedEventData: GroupedEventDBScheme
183-
) => Promise<mongodb.ObjectID>;
184-
};
185-
const originalSaveEvent = workerWithSaveEvent.saveEvent.bind(workerWithSaveEvent) as (
186-
projectId: string,
187-
groupedEventData: GroupedEventDBScheme
188-
) => Promise<mongodb.ObjectID>;
189-
let shouldThrowDuplicate = true;
190-
const saveEventSpy = jest.spyOn(workerWithSaveEvent, 'saveEvent');
191-
192-
saveEventSpy.mockImplementation(async (projectId: string, groupedEventData: GroupedEventDBScheme): Promise<mongodb.ObjectID> => {
193-
if (shouldThrowDuplicate) {
194-
shouldThrowDuplicate = false;
195-
196-
await originalSaveEvent(projectId, groupedEventData);
197-
198-
const duplicateError = new Error('duplicate key') as Error & { code: number };
199-
200-
duplicateError.code = duplicateKeyErrorCode;
201-
throw duplicateError;
202-
}
203-
204-
return originalSaveEvent(projectId, groupedEventData);
205-
});
206-
207-
await worker.handle(task);
208-
209-
expect(saveEventSpy).toHaveBeenCalledTimes(1);
210-
expect(await eventsCollection.find().count()).toBe(1);
211-
expect(await repetitionsCollection.find().count()).toBe(1);
212-
expect((await eventsCollection.findOne({})).totalCount).toBe(2);
213-
214-
saveEventSpy.mockRestore();
215-
});
216-
217176
test('Should increment total events count on each processing', async () => {
218177
await worker.handle(generateTask());
219178
await worker.handle(generateTask());

0 commit comments

Comments
 (0)