From 78928117be1cd4667a7642eda38fb47762cbbb49 Mon Sep 17 00:00:00 2001 From: "Filipe M. Silva" Date: Thu, 22 Aug 2024 21:32:53 -0300 Subject: [PATCH 1/3] fix: adjust promise on open DB --- src/client-connection.ts | 11 ++++++----- src/index.ts | 7 +++++-- tests/unit/client-connection.test.ts | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/client-connection.ts b/src/client-connection.ts index 28d95e8..2627edd 100644 --- a/src/client-connection.ts +++ b/src/client-connection.ts @@ -16,13 +16,14 @@ export class ClientConnection { return (MConnClient: MongoClient) => MConnClient; } - async connectOpen(dbName: string) { - await this.client.connect(); - this.dbInstance = await this.client.db(dbName); - return this.dbInstance; + async openConnect(dbName: string) { + return this.client.connect().then(() => { + this.dbInstance = this.client.db(dbName); + return this.dbInstance; + }); } - async collection(collectionName: string) { + collection(collectionName: string) { return this.dbInstance.collection(collectionName); } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 4316192..a0090b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,8 +18,11 @@ export class SimpleConnection extends ClientConnection { this.dbName = dbName; } - async open() { + open() { this.client = new MongoClient(this.connectionString); - await super.connectOpen(this.dbName); + return new Promise((resolve, reject) => { + super.openConnect(this.dbName) + .then((db) => resolve(db)); + }); } } \ No newline at end of file diff --git a/tests/unit/client-connection.test.ts b/tests/unit/client-connection.test.ts index cc14c04..64a9361 100644 --- a/tests/unit/client-connection.test.ts +++ b/tests/unit/client-connection.test.ts @@ -29,18 +29,18 @@ describe("Unit Test for ClientConnection", () => { }); it("expect connectOpen calls client connect", async () => { - await db.connectOpen("test"); + await db.openConnect('test'); expect(dbMethodsStub.connect.called).to.be.true; }); it("expect connectOpen calls client db", async () => { - await db.connectOpen("test"); + await db.openConnect('test'); expect(dbMethodsStub.db.called).to.be.true; }); it("expect collection calls dbInstance collection", async () => { - await db.connectOpen("test"); - await db.collection("test"); + const dbInstance = await db.openConnect('test'); + dbInstance.collection('test'); expect(collectionStub.collection.called).to.be.true; }); }); \ No newline at end of file From 612c3e394a3041cd36eae2ee206408f57273ea56 Mon Sep 17 00:00:00 2001 From: "Filipe M. Silva" Date: Thu, 22 Aug 2024 21:41:01 -0300 Subject: [PATCH 2/3] ci: fix docker compose command --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7fa70fd..8c873f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,4 +52,4 @@ jobs: MONGO_INITDB_ROOT_PASSWORD: ${{secrets.MONGO_INITDB_ROOT_PASSWORD}} MONGO_INITDB_DATABASE: ${{vars.MONGO_INITDB_DATABASE}} - name: - run: docker-compose up -d + run: docker compose up -d From 2551f0b186b8ee7f07f52cb19595deee1f756884 Mon Sep 17 00:00:00 2001 From: "Filipe M. Silva" Date: Thu, 22 Aug 2024 22:10:19 -0300 Subject: [PATCH 3/3] ci: fix docker mongodb health check --- docker-compose.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d0557a4..57fdab6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,13 @@ services: hostname: mongodb7 networks: - alpine_net + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongosh 127.0.0.1:27017/test --quiet + start_period: 30s + start_interval: 30s + interval: 5s + timeout: 30s + retries: 50 deploy: resources: limits: @@ -31,7 +38,8 @@ services: ports: - 3000:3000 depends_on: - - mongodb7 + mongodb7: + condition: service_healthy networks: - alpine_net