Skip to content

Backend: add a graceful-shutdown drain test asserting in-flight exports complete before process exit #1739

Description

@Baskarayelu

📋 Description

Shutdown ordering lives in shutdown.ts and is wired from bootstrap.ts. Exports run as longer-lived jobs via exportService.ts. There is no test proving that on SIGTERM the shutdown sequence waits for in-flight export jobs to finish (or checkpoint) before closing the DB and exiting.

Why this matters: killing the process mid-export corrupts or loses the artifact. A drain test pins the contract that shutdown waits for in-flight work, preventing a regression that reorders teardown.

🎯 Requirements & Context

  • Add a jest suite that starts a simulated in-flight export, triggers the shutdown sequence, and asserts the export completes (or checkpoints) before the DB-close step runs.
  • Assert new requests are rejected once draining begins.
  • Assert a bounded drain timeout forces teardown if a job hangs (no infinite wait).
  • Use fake timers for the timeout path.

Context & constraints

  • TypeScript, jest. Mock the export job's completion signal; do not perform real file I/O.

🛠️ Suggested Execution

git checkout -b test/shutdown-export-drain
npm --prefix backend test -- shutdown
  • Edge cases: no in-flight jobs (immediate teardown); job finishes just before timeout; job exceeds timeout (forced); multiple concurrent exports.

Example commit message

test(backend): assert shutdown drains in-flight exports before DB close

Pins the teardown ordering and the bounded drain-timeout fallback.

✅ Acceptance Criteria & Guidelines

Requirement Target
Drain-before-close asserted Required
Bounded timeout fallback covered Required
Coverage of shutdown sequence ≥ 95%
jest + lint clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Join Discord: https://discord.gg/VpngvTjWa — comment to claim. 🚀

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions