Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(session): pin the write scope reopening after a failed delete
Yudhi Armyndharisd7dad4bbd0da
diff --git a/src/modules/session/session-content-lifetime.spec.ts b/src/modules/session/session-content-lifetime.spec.tsindex e1d9a179a..5834c6da9 100644--- a/src/modules/session/session-content-lifetime.spec.ts+++ b/src/modules/session/session-content-lifetime.spec.ts@@ -27,6 +27,7 @@ import { SendPacingService } from '../message/send-pacing.service';import { StatusStoreService } from '../status-store/status-store.service';import { StorageService } from '../../common/storage/storage.service';import { EngineNotReadyError } from '../../common/errors/engine-not-ready.error';+import { captureSessionWrites } from '../../common/utils/session-write-scope';function deferred<T = void>() {let resolve!: (value: T | PromiseLike<T>) => void;@@ -420,6 +421,21 @@ describe('Session content lifetime', () => {expect(await db.getRepository(Session).countBy({ id: session.id })).toBe(1);});+ // Left closed, every later send, bulk batch and status ingest of the session fails until the process restarts.+ it('reopens the write scope of the surviving session', async () => {+ const session = await createSession();+ jest.spyOn(db, 'transaction').mockRejectedValueOnce(new Error('canceling statement due to statement timeout'));++ await expect(controls.delete(session.id)).rejects.toThrow('statement timeout');++ const scope = captureSessionWrites(db, session.id);+ try {+ expect(() => scope.assertCurrent()).not.toThrow();+ } finally {+ scope.close();+ }+ });+it('leaves the batches alone when the delete is refused before it closes anything', async () => {const session = await createSession();await seedBatch(session.id, BatchStatus.PROCESSING, 'b-processing');