This repository was archived by the owner on Oct 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
π Bug Report: Pulse Worker Cleanup Issue in Fastify 5.x IntegrationΒ #74
Copy link
Copy link
Open
Description
Description
I am integrating Pulse into my Fastify 5.x application and writing a spec to test the integration. The test itself runs as expected, but I am encountering the following warning message when Jest completes execution:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
It appears that worker.stop() does not properly clean up the worker after the test completes, leading to Jest detecting an open handle.
Steps to Reproduce
- Use Pulse with the following configuration:
const workerConfig: PulseConfig = { db: { address: mongoURI, collection: "jobs_test" }, processEvery: "2 seconds", maxConcurrency: 4, disableAutoIndex: false, defaultConcurrency: 5, }; - Define and start the worker in
beforeAll:worker = new Pulse(workerConfig); await worker.start(); - Stop the worker and in-memory MongoDB in
afterAll:await worker.stop(); await mongoServer.stop(); - Run the test suite with Jest.
Expected Behavior
- Jest should exit cleanly after tests complete.
worker.stop()should correctly clean up all resources.
Actual Behavior
- Jest does not exit after tests complete.
- The warning suggests open asynchronous operations are still running, possibly from Pulse's internal processes.
Possible Solutions Explored
- Running Jest with
--detectOpenHandlesconfirms the issue is related to Pulse. - Ensured
worker.stop()is called inafterAll, but it does not resolve the issue.
Environment
| Dependency | Version |
|---|---|
| Fastify | 5.x |
| Pulse | @pulsecron/pulse latest |
| Jest | x.x.x |
| Node.js | x.x.x |
| MongoMemoryServer | latest |
Additional Context
Would appreciate any guidance on whether Pulse requires additional cleanup beyond worker.stop() or if there is an open issue regarding resource cleanup.
Thank you! π
Here is my full spec
//tests/pulse.spec.ts
/* eslint-disable @typescript-eslint/no-explicit-any */
import Pulse, { Job, PulseConfig } from "@pulsecron/pulse";
import { MongoMemoryServer } from "mongodb-memory-server";
describe("worker", () => {
let worker: Pulse;
let mongoServer: MongoMemoryServer;
beforeAll(async () => {
// Start an in-memory MongoDB server
mongoServer = await MongoMemoryServer.create();
const mongoURI = mongoServer.getUri();
console.log("Mongo URI: ", mongoURI);
const workerConfig: PulseConfig = {
db: { address: mongoURI, collection: "jobs_test" },
processEvery: "2 seconds",
maxConcurrency: 4,
disableAutoIndex: false,
defaultConcurrency: 5, // Max 5 jobs running at the same time
};
worker = new Pulse(workerConfig);
await worker.start();
});
afterAll(async () => {
console.log("Stopping worker");
await worker.stop();
console.log("Stopping mongoServer");
await mongoServer.stop();
});
it("should have a default concurrency of 5", async () => {
worker.define("with_arg_job", async (job: Job) => {
console.info("Executing job: with_arg_job", job.attrs.data);
});
worker.define("without_arg_job", async () => {
console.info("Executing job: without_arg_job");
});
await worker.create("with_arg_job", { email: "test@pulse.org" }).save();
await worker.create("without_arg_job", {}).save();
});
});Test output
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
