Skip to content

Replace process.exit with graceful connection close in test cleanup - #222

Open
BismaKodes wants to merge 1 commit into
madhums:masterfrom
BismaKodes:fix-process-exit-149
Open

BismaKodes wants to merge 1 commit into
madhums:masterfrom
BismaKodes:fix-process-exit-149

Conversation

@BismaKodes

Copy link
Copy Markdown

Fixes #149

Replaces the forced process.exit(0) in the test cleanup with a graceful
shutdown of the mongoose connection instead.

  • Calls connection.close() to properly close the database connection.
  • Removes the disconnected event listener before closing. The app is set
    up to auto-reconnect whenever the connection disconnects
    (connection.on('disconnected', connect) in server.js). Without removing
    this listener first, calling .close() would immediately trigger a new
    reconnect, causing the process to hang indefinitely instead of exiting
    cleanly.

This avoids force-killing the process and lets Node exit naturally once
the connection is properly closed.

Note: I noticed that running npm test currently reports # tests 0
regardless of the cleanup method used — this appears to be a separate,
pre-existing issue (possibly related to session store / connection timing
on the "Home page" test) rather than something caused by this change.
Happy to investigate further in a separate issue/PR if that would be useful.

@BismaKodes BismaKodes mentioned this pull request Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup?

2 participants