From c73504e0ed3178d18274ba3ea7b361bf5ed6ef5d Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Sat, 15 Mar 2025 13:42:38 +0100 Subject: [PATCH] fix(workflow-engine-inmemory): Fail trap for integration tests (#11839) **What** Jest is patching the event emitter meaning that sometimes it can lead to flacky behaviors and block the test execution if the done callback is never reached. To prevent that from happening, the fail trap will call the done callback after a given time and warn that the test could not be concluded because of jest blocking it --- .../integration-tests/__tests__/index.spec.ts | 15 +++++++++++++++ .../integration-tests/__tests__/race.spec.ts | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts index bee8c94d41..241e4da9ed 100644 --- a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts +++ b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts @@ -28,10 +28,21 @@ import { workflowEventGroupIdStep1Mock, workflowEventGroupIdStep2Mock, } from "../__fixtures__/workflow_event_group_id" +import { setTimeout as setTimeoutSync } from "timers" import { createScheduled } from "../__fixtures__/workflow_scheduled" jest.setTimeout(3000000) +const failTrap = (done) => { + setTimeoutSync(() => { + // REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending + console.warn( + "Jest is breaking the event emit with its debouncer. This allows to continue the test by managing the timeout of the test manually." + ) + done() + }, 5000) +} + moduleIntegrationTestRunner({ moduleName: Modules.WORKFLOW_ENGINE, resolve: __dirname + "/../..", @@ -307,6 +318,8 @@ moduleIntegrationTestRunner({ }, throwOnError: true, }) + + failTrap(done) }) it("should not run conditional steps if condition is false", (done) => { @@ -327,6 +340,8 @@ moduleIntegrationTestRunner({ }, throwOnError: true, }) + + failTrap(done) }) }) diff --git a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/race.spec.ts b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/race.spec.ts index 8da509ad8a..2b87bdfab7 100644 --- a/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/race.spec.ts +++ b/packages/modules/workflow-engine-inmemory/integration-tests/__tests__/race.spec.ts @@ -14,6 +14,16 @@ import "../__fixtures__" jest.setTimeout(3000000) +const failTrap = (done) => { + setTimeoutSync(() => { + // REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending + console.warn( + "Jest is breaking the event emit with its debouncer. This allows to continue the test by managing the timeout of the test manually." + ) + done() + }, 5000) +} + moduleIntegrationTestRunner({ moduleName: Modules.WORKFLOW_ENGINE, resolve: __dirname + "/../..", @@ -87,6 +97,8 @@ moduleIntegrationTestRunner({ expect(result).toBe("result from step 0") }) .catch((e) => e) + + failTrap(done) }) it("should prevent race continuation of the workflow compensation during retryIntervalAwaiting in background execution", (done) => { @@ -176,6 +188,8 @@ moduleIntegrationTestRunner({ expect(result).toBe("result from step 0") }) .catch((e) => e) + + failTrap(done) }) }) },