From 7084e8d35fd7c5ff22c66edcad98550c538c766f Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Thu, 4 Jul 2024 21:48:51 +0800 Subject: [PATCH] chore(ci): release database after closed (#4819) * chore(ci): release database after closed * chore: clean database * chore: test --- .github/workflows/nocobase-test-backend.yml | 2 +- .../core/test/src/scripts/test-db-creator.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nocobase-test-backend.yml b/.github/workflows/nocobase-test-backend.yml index 6731cf64e0..6fb34b1ff8 100644 --- a/.github/workflows/nocobase-test-backend.yml +++ b/.github/workflows/nocobase-test-backend.yml @@ -111,7 +111,7 @@ jobs: DB_SCHEMA: ${{ matrix.schema }} COLLECTION_MANAGER_SCHEMA: ${{ matrix.collection_schema }} DB_TEST_DISTRIBUTOR_PORT: 23450 - DB_TEST_PREFIX: test_ + DB_TEST_PREFIX: test timeout-minutes: 60 mysql-test: diff --git a/packages/core/test/src/scripts/test-db-creator.ts b/packages/core/test/src/scripts/test-db-creator.ts index f76289a19e..edd7358b4a 100644 --- a/packages/core/test/src/scripts/test-db-creator.ts +++ b/packages/core/test/src/scripts/test-db-creator.ts @@ -36,6 +36,11 @@ abstract class BaseClient { await this._createDB(name); this.createdDBs.add(name); + + // remove db after 3 minutes + setTimeout(async () => { + await this.removeDB(name); + }, 3 * 60 * 1000); } async releaseAll() { @@ -51,6 +56,16 @@ abstract class BaseClient { this.createdDBs.delete(name); } } + + async removeDB(name: string) { + if (!this._client) { + return; + } + if (this.createdDBs.has(name)) { + await this._removeDB(name); + this.createdDBs.delete(name); + } + } } class PostgresClient extends BaseClient { @@ -156,8 +171,9 @@ const server = http.createServer((req, res) => { res.end(JSON.stringify({ error })); }); } else if (trimmedPath === 'release') { + const name = parsedUrl.query.name as string | undefined; dbClient - .releaseAll() + .removeDB(name) .then(() => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end();