testcontainers-node icon indicating copy to clipboard operation
testcontainers-node copied to clipboard

Jest hangs on Gitlab CI due to leaks

Open juanfernandez-gh opened this issue 5 years ago • 5 comments

[email protected]

When running tests on the pipline the job keeps running until timeout, test pass but it doesn't exit from the tests and this message shows in the console:

Jest did not exit one second after the test run has completed.

And if I run the test locally I get this warning:

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.

using the leaked-handles package and running the tests with --detectOpenHandles flag I get the following locally:

no of handles 3

tcp stream {
  fd: 1,
  readable: false,
  writable: true,
  address: {},
  serverAddr: null
}

tcp stream {
  fd: 2,
  readable: false,
  writable: true,
  address: {},
  serverAddr: null
}

tcp stream {
  fd: 0,
  readable: true,
  writable: false,
  address: {},
  serverAddr: null
}

not sure if those logs help, but I think this issue should be addressed, I could use --forceExit as a workaround but It'd be best if this is solved from its origin.

This is the function that starts the container:

export const initMongoDBContainer = async () => {
    try {        
        mongoContainer = <StartedGenericContainer> await new GenericContainer("mongo")
        .withExposedPorts(MONGODB_DEFAULT_PORT)
        .start();
        const MAPPED_PORT = mongoContainer.getMappedPort(MONGODB_DEFAULT_PORT);
        process.env.MONGODB_URL = `mongodb://${mongoContainer.getHost()}:${MAPPED_PORT}/db-data`;
        process.env.MONGODB_DEFAULT_PORT = String(MONGODB_DEFAULT_PORT);
        return mongoContainer;
    } catch(e) {
        console.error(`Error initializing mongo container: ${e}`);
    }
};

These are the logs from testcontainers:

2021-07-13T17:32:48.772Z testcontainers DEBUG Creating new DockerClient
2021-07-13T17:32:48.775Z testcontainers INFO  Detected DOCKER_HOST environment variable: tcp://docker:2375
2021-07-13T17:32:48.775Z testcontainers INFO  Using Docker host from modem: docker
2021-07-13T17:32:48.813Z testcontainers WARN  Unable to detect docker-compose version, is it installed?
2021-07-13T17:32:48.814Z testcontainers DEBUG System diagnostics: {
  "node": {
    "version": "v10.15.3",
    "architecture": "x64",
    "platform": "linux"
  },
  "docker": {
    "serverVersion": "20.10.7",
    "operatingSystem": "Alpine Linux v3.13 (containerized)",
    "operatingSystemType": "linux",
    "architecture": "x86_64",
    "cpus": 1,
    "memory": 3873349632
  }
}
2021-07-13T17:32:48.819Z testcontainers DEBUG No registry auth locator found for registry: "https://index.docker.io/v1/"
2021-07-13T17:32:48.819Z testcontainers INFO  Pulling image: mongo:latest
2021-07-13T17:32:49.349Z testcontainers TRACE Pulling mongo:latest - latest - Pulling from library/mongo
2021-07-13T17:32:49.481Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Pulling fs layer
2021-07-13T17:32:49.481Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Pulling fs layer
2021-07-13T17:32:49.482Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Pulling fs layer
2021-07-13T17:32:49.482Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Pulling fs layer
2021-07-13T17:32:49.483Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Pulling fs layer
2021-07-13T17:32:49.483Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Pulling fs layer
2021-07-13T17:32:49.484Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Pulling fs layer
2021-07-13T17:32:49.484Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Pulling fs layer
2021-07-13T17:32:49.485Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Pulling fs layer
2021-07-13T17:32:49.485Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Pulling fs layer
2021-07-13T17:32:49.486Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Waiting
2021-07-13T17:32:49.486Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Waiting
2021-07-13T17:32:49.487Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Waiting
2021-07-13T17:32:49.488Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Waiting
2021-07-13T17:32:49.488Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Waiting
2021-07-13T17:32:49.488Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Waiting
2021-07-13T17:32:49.489Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Waiting
2021-07-13T17:32:49.654Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Downloading 35%
2021-07-13T17:32:49.655Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Downloading 100%
2021-07-13T17:32:49.656Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Verifying Checksum
2021-07-13T17:32:49.657Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Download complete
2021-07-13T17:32:49.658Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Downloading 1%
2021-07-13T17:32:49.686Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Downloading 1%
2021-07-13T17:32:49.730Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Verifying Checksum
2021-07-13T17:32:49.731Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Download complete
2021-07-13T17:32:49.787Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Downloading 33%
2021-07-13T17:32:49.864Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Downloading 1%
2021-07-13T17:32:49.891Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Downloading 60%
2021-07-13T17:32:49.921Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Downloading 100%
2021-07-13T17:32:49.922Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Verifying Checksum
2021-07-13T17:32:49.923Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Download complete
2021-07-13T17:32:49.975Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Downloading 77%
2021-07-13T17:32:49.988Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Verifying Checksum
2021-07-13T17:32:49.989Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Download complete
2021-07-13T17:32:49.990Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Downloading 94%
2021-07-13T17:32:49.998Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Verifying Checksum
2021-07-13T17:32:49.999Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Download complete
2021-07-13T17:32:50.060Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Extracting
2021-07-13T17:32:50.158Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Downloading 46%
2021-07-13T17:32:50.159Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Downloading 100%
2021-07-13T17:32:50.160Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Verifying Checksum
2021-07-13T17:32:50.161Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Download complete
2021-07-13T17:32:50.215Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Downloading 100%
2021-07-13T17:32:50.217Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Verifying Checksum
2021-07-13T17:32:50.217Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Download complete
2021-07-13T17:32:50.250Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 0%
2021-07-13T17:32:50.358Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 6%
2021-07-13T17:32:50.415Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Downloading 100%
2021-07-13T17:32:50.416Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Verifying Checksum
2021-07-13T17:32:50.416Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Download complete
2021-07-13T17:32:50.475Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 18%
2021-07-13T17:32:50.516Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Downloading 15%
2021-07-13T17:32:50.517Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Downloading 100%
2021-07-13T17:32:50.518Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Verifying Checksum
2021-07-13T17:32:50.519Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Download complete
2021-07-13T17:32:50.565Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 28%
2021-07-13T17:32:50.666Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 37%
2021-07-13T17:32:50.780Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 45%
2021-07-13T17:32:50.881Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 50%
2021-07-13T17:32:50.982Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 53%
2021-07-13T17:32:51.107Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 55%
2021-07-13T17:32:51.221Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 60%
2021-07-13T17:32:51.333Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 63%
2021-07-13T17:32:51.427Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 65%
2021-07-13T17:32:51.552Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 71%
2021-07-13T17:32:51.638Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 78%
2021-07-13T17:32:51.739Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 84%
2021-07-13T17:32:51.856Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 90%
2021-07-13T17:32:51.958Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Downloading 96%
2021-07-13T17:32:52.059Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Verifying Checksum
2021-07-13T17:32:52.060Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Download complete
2021-07-13T17:32:54.046Z testcontainers TRACE Pulling mongo:latest - 25fa05cd42bd - Pull complete
2021-07-13T17:32:54.078Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Extracting
2021-07-13T17:32:54.148Z testcontainers TRACE Pulling mongo:latest - 3380d70bde1c - Pull complete
2021-07-13T17:32:54.162Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Extracting
2021-07-13T17:32:54.430Z testcontainers TRACE Pulling mongo:latest - 9c5e30e9886d - Pull complete
2021-07-13T17:32:54.438Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Extracting
2021-07-13T17:32:54.795Z testcontainers TRACE Pulling mongo:latest - c6583381983d - Pull complete
2021-07-13T17:32:54.803Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Extracting
2021-07-13T17:32:54.864Z testcontainers TRACE Pulling mongo:latest - 7873a2834540 - Pull complete
2021-07-13T17:32:54.871Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Extracting
2021-07-13T17:32:54.931Z testcontainers TRACE Pulling mongo:latest - 5550b05263ab - Pull complete
2021-07-13T17:32:54.939Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Extracting
2021-07-13T17:32:55.000Z testcontainers TRACE Pulling mongo:latest - f8c53eb02c3e - Pull complete
2021-07-13T17:32:55.085Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Extracting
2021-07-13T17:33:01.763Z testcontainers TRACE Pulling mongo:latest - 36d83d0aa258 - Pull complete
2021-07-13T17:33:01.772Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Extracting
2021-07-13T17:33:01.866Z testcontainers TRACE Pulling mongo:latest - b6790a091c8a - Pull complete
2021-07-13T17:33:01.877Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Extracting
2021-07-13T17:33:01.954Z testcontainers TRACE Pulling mongo:latest - 8cc2814c4956 - Pull complete
2021-07-13T17:33:01.977Z testcontainers TRACE Pulling mongo:latest - Digest: sha256:fe44eb6a2ea2bb1548718ec05eb9cb165f1bded37595ebea507bddc413ab99ae
2021-07-13T17:33:01.983Z testcontainers TRACE Pulling mongo:latest - Status: Downloaded newer image for mongo:latest
2021-07-13T17:33:01.991Z testcontainers DEBUG Creating new Reaper for session: 00d8fd9852a0a3f08ff3f762017f1697
2021-07-13T17:33:02.026Z testcontainers DEBUG No registry auth locator found for registry: "https://index.docker.io/v1/"
2021-07-13T17:33:02.027Z testcontainers INFO  Pulling image: cristianrgreco/ryuk:0.4.0
2021-07-13T17:33:02.497Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 0.4.0 - Pulling from cristianrgreco/ryuk
2021-07-13T17:33:02.498Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Pulling fs layer
2021-07-13T17:33:02.499Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Pulling fs layer
2021-07-13T17:33:02.499Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Pulling fs layer
2021-07-13T17:33:02.674Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Downloading 1%
2021-07-13T17:33:02.679Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Downloading 1%
2021-07-13T17:33:02.680Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Downloading 1%
2021-07-13T17:33:02.713Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Downloading 100%
2021-07-13T17:33:02.714Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Verifying Checksum
2021-07-13T17:33:02.715Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Download complete
2021-07-13T17:33:02.751Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Verifying Checksum
2021-07-13T17:33:02.752Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Download complete
2021-07-13T17:33:02.762Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Extracting
2021-07-13T17:33:02.765Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Verifying Checksum
2021-07-13T17:33:02.766Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Download complete
2021-07-13T17:33:02.974Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Pull complete
2021-07-13T17:33:02.981Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Extracting
2021-07-13T17:33:03.244Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Pull complete
2021-07-13T17:33:03.248Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Extracting
2021-07-13T17:33:03.404Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Pull complete
2021-07-13T17:33:03.418Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - Digest: sha256:e1f13eca329e43f03f38786406507c65162e63acd35e7d4c3708b25a6c80f791
2021-07-13T17:33:03.423Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - Status: Downloaded newer image for cristianrgreco/ryuk:0.4.0
2021-07-13T17:33:03.427Z testcontainers INFO  Creating container for image: cristianrgreco/ryuk:0.4.0
2021-07-13T17:33:03.673Z testcontainers INFO  Starting container cristianrgreco/ryuk:0.4.0 with ID: 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.592Z testcontainers DEBUG Waiting for container to be ready: 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.593Z testcontainers DEBUG Waiting for host port 49144 for 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.595Z testcontainers DEBUG Waiting for internal port 8080 for 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.600Z testcontainers DEBUG Host port 49144 ready for 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.837Z testcontainers DEBUG Internal port 8080 ready for 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.838Z testcontainers INFO  Container is ready
2021-07-13T17:33:04.838Z testcontainers DEBUG Connecting to Reaper 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b on docker:49144
2021-07-13T17:33:04.840Z testcontainers DEBUG Connected to Reaper 7bea87f8d328c91cc5c41c194fb03a274556c5c633190dbf93ff025d8a5dc82b
2021-07-13T17:33:04.840Z testcontainers INFO  Creating container for image: mongo:latest
2021-07-13T17:33:04.879Z testcontainers INFO  Starting container mongo:latest with ID: 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:05.453Z testcontainers DEBUG Waiting for container to be ready: 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:05.454Z testcontainers DEBUG Waiting for host port 54766 for 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:05.454Z testcontainers DEBUG Waiting for internal port 27017 for 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:07.172Z testcontainers DEBUG Host port 54766 ready for 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:08.599Z testcontainers DEBUG Internal port 27017 ready for 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf
2021-07-13T17:33:08.600Z testcontainers INFO  Container is ready
2021-07-13T17:33:08.630Z testcontainers INFO  Stopping container with ID: 819acb40f25aea37e62b216256f4d43ae7e736d9223c7ae063ee7b9ef1b147bf

juanfernandez-gh avatar Jul 13 '21 17:07 juanfernandez-gh

@juanf9224, the testcontainers-node pipeline runs many tests which start and stop containers and they terminate as expected, why do you think this is an issue with testcontainers and not the test/CI environment?

are you stopping the container? if you are then please share more code, ideally a reproducible example. All I can see from the log is that the mongo container started to stop and then nothing

cristianrgreco avatar Jul 13 '21 17:07 cristianrgreco

thanks for the reply @cristianrgreco , as I mentioned, locally it has the leakes as well, the leaked-handles log is from my local environment.

this is the test that's causing the job to hang:

import { Db } from 'mongodb';
import { initContainerDB, stopDbContainer } from './setupMongoContainer';

jest.setTimeout(70000);
describe('Test container suite', () => {
    let db: Db;

    beforeAll(async () => {
        db = await initContainerDB();
    });

    afterAll(async () => {
        await stopDbContainer();
    })

    test('database should be initialized', async () => {
        expect(db).toBeTruthy();
        expect(db?.databaseName).toBe('db-data');
    })
});

and this is the mongo container file being used:

import { GenericContainer } from "testcontainers";
import { StartedGenericContainer } from "testcontainers/dist/generic-container";
import { mongoDB } from "utils/db";
const MONGODB_DEFAULT_PORT = 27017;
let mongoContainer: StartedGenericContainer;

/**
 * Helper function to asynchronously create a Test Docker Container of a Mongo Instance
 */
export const initMongoDBContainer = async () => {
    try {        
        mongoContainer = <StartedGenericContainer> await new GenericContainer("mongo")
        .withExposedPorts(MONGODB_DEFAULT_PORT)
        .start();
        const MAPPED_PORT = mongoContainer.getMappedPort(MONGODB_DEFAULT_PORT);
        process.env.MONGODB_URL = `mongodb://${mongoContainer.getHost()}:${MAPPED_PORT}/garden-data`;
        process.env.MONGODB_DEFAULT_PORT = String(MONGODB_DEFAULT_PORT);
        return mongoContainer;
    } catch(e) {
        console.error(`Error initializing mongo container: ${e}`);
    }
};

export const initContainerDB = async () => {
    // Start the docker container
    await initMongoDBContainer();
    return mongoDB.getInstance();
};

export const stopDbContainer = async () => {
    if (mongoContainer) {
        await mongoContainer.stop();
        console.log("Container stopped successfully");
    } else {
        console.log("Container not initialized");
    }
};

If I remove this test or stop using the container, the test job doesn't hangs.

juanfernandez-gh avatar Jul 13 '21 18:07 juanfernandez-gh

the example doesn't run, what is import { mongoDB } from "utils/db"; ?

i will guess that it's some function which instantiates and connects aMongoClient and returns a Db, but the client is not being disconnected (mongoClient.close()) at the end of the test run


as a side note, here are a couple of code improvements you could make:

// before
import { GenericContainer } from "testcontainers";
import { StartedGenericContainer } from "testcontainers/dist/generic-container";

// after
import { GenericContainer, StartedGenericContainer } from "testcontainers";

---

// before
mongoContainer = <StartedGenericContainer> await new GenericContainer("mongo")...

// after
mongoContainer = await new GenericContainer("mongo")...

cristianrgreco avatar Jul 13 '21 19:07 cristianrgreco

Thanks! @cristianrgreco , closing the mongo connection solved the issue, as per your recommendations for the version I'm using, it says that testcontainers has no exported member StartedGenericContainer, and the mongo container is of type StartedGenericContainer but new GenericContainer() returns a GenericContainer not a StartedGenericContainer which I get from the statrt() function that's chained in my code.

juanfernandez-gh avatar Jul 13 '21 22:07 juanfernandez-gh

@juanf9224 apologies, I meant StartedTestContainer. I've updated the README to show example TypeScript usage. Glad it’s resolved now 👍

cristianrgreco avatar Jul 13 '21 22:07 cristianrgreco