Skip to content

Destroy doesn't terminate server - port blocked #18

Open

Description

@przemyslaw-maslowski

I'm thinking about using this repo for testing and I've encountered a problem in Jest.
If I start tests by defining a postgres mock, by PostgresMock.create() then .listen() and later at the end of the tests end it with .destroy() (I don't think there's any other way to do it), then when I run the tests again (without ending the process) I get a message that the port is taken.

I reviewed the code and it seems to me that the problem is the server created in listen(), which is not closed by destroy().

My solution is to save the created server in some private variable and in the destroy() method end it with .close();.
I tested it locally and the solution releases the port, eliminating the problem.

Activity

  1. s-p-sathish commented on Dec 5, 2024

    @s-p-sathish

    @przemyslaw-maslowski before running again please kill the port use eg: npx kill-port 5432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions