Skip to content

[BUG] shutdown.test.js: Mock connections not properly cleaned up during shutdown #129

@jeloskaisabel

Description

@jeloskaisabel

Describe the bug

__tests__/server/shutdown.test.js fails with a timeout after 5000 ms because mock connections aren’t removed from server.connections during shutdown.
server.stop() waits until shutdownTimeout expires, and Jest times out.
Mock methods like mockConnState.close() or mockSocket.destroy() don’t emit the real events ('close', 'end') expected by _performGracefulShutdown().

This happens both inside the Dev Container and locally (just running npm install + npm test).


To Reproduce

npm test -- --runInBand

shutdown.test.js times out after 5000 ms.
Same result if tests are run inside the Docker dev container.


Expected behavior

server.stop() should gracefully close all mock connections and complete before reaching the shutdown timeout, allowing the test to finish normally.


Console output

FAIL __tests__/server/shutdown.test.js
  ● should rollback transactions during shutdown
    Exceeded timeout of 5000 ms for a test.
Jest did not exit one second after the test run has completed.

Environment

Component Version / Info
pg-wire-mock main (1.1.0)
Node.js v22.x
OS Windows 11 / Ubuntu 22.04 / Docker base image
Command npm test -- --runInBand

Additional context

  • Mock connections persist in server.connections, blocking _performGracefulShutdown().
  • Increasing Jest timeout only hides the issue.

Likely fix: mock sockets should emit 'close'/'end' so cleanup runs properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions