Skip to content

Can't seem to run unit tests nor coverage tests locally with MySQL in a docker container, tests seems to randomly hang/stall. #3854

@HappyZombies

Description

@HappyZombies

Hey there, I am looking to contribute to this package =)

I started by reading the contribution guide and it said how to run the tests. So I decide to run the unit tests to make sure all is green before I start adding/changing stuff lol

But I ran into a problem running them locally, I see that they definelty all do run according to this action run.

But running them locally I am not having success, they seem to intermiately halt/stall at random points during the test run.

Repo Steps:

  1. Docker Compose
services:
  mysql:
    image: mysql:8.0
    # platform: linux/amd64  --- add if on M1
    container_name: mysql-v8.0
    environment:
      MYSQL_ROOT_PASSWORD: "somepassword"
      MYSQL_DATABASE: test
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql

Run docker compose up -d

  1. Made a launch.json for VSCode
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug npm test (poku)",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "test"
            ],
            "port": 9229,
            "env": {
                "CI": "1",
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_USER": "root",
                "MYSQL_PASSWORD": "somepassword",
                "MYSQL_DATABASE": "node_test"
            },
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }
    ]
}

Or simply just exported it

export CI=1
export MYSQL_HOST=127.0.0.1
export MYSQL_USER=root
export MYSQL_PASSWORD=somepassword
export MYSQL_DATABASE=node_test

NOTE: I noticed that the tests continue down a lot further IF I set MYSQL_HOST to 127.0.0.1, if I use localhost or 0.0.0.0, they stop a lot earlier at test/esm/unit/check-extensions.test.mjs, always.

  1. Run npm run test

Expected:

All tests should run and complete.

Actual:

The test runner sometimes hangs or stops at different spots. Sometimes only a few tests run, sometimes more, but it never completes. This only happens locally; in CI all tests pass.

Here is where the tests stop running.

› test/esm/regressions/2052.test.mjs › 103.412708ms
  🔬 Unit Test - Prepare result with number of parameters incorrectly reported by the server
  ✔ should report 0 actual parameters when 1 placeholder is used in ORDER BY ?
  ✔ expect no error
  ✔ parameters
  ✔ columns
  ✔ id
  🔬 E2E Prepare result with number of parameters incorrectly reported by the server
  ✔ parameters length needs to be 1
  ✔ parameters length needs to be 2

› test/esm/unit/check-extensions.test.mjs › 72.220084ms
  ✔ Check for invalid file types found in restricted directories

And if I set MYSQL_HOST to 127.0.0.1, they tend to stop here but not all the time.

› test/esm/unit/check-extensions.test.mjs › 238.099792ms
  Debugger attached.
  ✔ Check for invalid file types found in restricted directories
  Waiting for the debugger to disconnect...

› test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs › 292.063250ms
  Debugger attached.
  🔬 Test pool cluster
  ✔ should propagate warn event to promise wrapper
  ✔ should propagate remove event to promise wrapper
  ✔ should propagate offline event to promise wrapper
  ✔ should propagate online event to promise wrapper
  ✔ should get connection
  ✔ should query successfully
  ✔ should execute successfully
  ✔ should throw when PoolNamespace does not exist
  ✔ should match regex pattern
  Waiting for the debugger to disconnect...

Any ideas on what could cause this or how to debug further?

Some other notes:

Docker version 28.4.0, build d8eb465

 node -v
v22.14.0

 npm -v
10.9.2

 mysql --version (inside a docker container)
mysql  Ver 8.0.43 for Linux on x86_64 (MySQL Community Server - GPL)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions