From 53b3c1fa0049daa21b123ce98ce3c8b6e482fd7c Mon Sep 17 00:00:00 2001 From: Pascal Jufer Date: Tue, 18 Jun 2024 11:37:20 +0200 Subject: [PATCH] Fix remaining blackbox test issues (#22759) * Fix remaining blackbox test issues * Temporary activation of blackbox tests (sqlite) * Enable hanging-process reporter for now * Revert "Enable hanging-process reporter for now" This reverts commit ce490ba229c0be6e983ce7728d8a2772cd8065c2. * Fix hanging by cleaning up sequential list Also prevent this issue in future by logging invalid files in list * Switch remaining tests to `getPort` To get random, available ports * Revert "Temporary activation of blackbox tests (sqlite)" This reverts commit a8687a095a8933d91dd60d7332c933c01a24f6bb. --- pnpm-lock.yaml | 238 +++++++++++++++++- tests/blackbox/common/functions.ts | 2 +- tests/blackbox/package.json | 2 +- tests/blackbox/setup/sequencer.ts | 6 + tests/blackbox/setup/sequential-tests.ts | 1 - .../blackbox/tests/common/assets/read.test.ts | 46 ++-- .../tests/common/flows/schedule-hook.test.ts | 21 +- .../tests/common/logger/redact.test.ts | 17 +- tests/blackbox/tests/db/app/cache.test.ts | 19 +- .../routes/collections/schema-cache.test.ts | 8 +- .../tests/db/routes/flows/webhook.test.ts | 7 +- .../db/routes/permissions/cache-purge.test.ts | 4 +- .../tests/db/routes/server/health.test.ts | 11 - .../timezone-changed-node-tz-america.test.ts | 33 +-- .../timezone-changed-node-tz-asia.test.ts | 35 ++- .../blackbox/tests/db/websocket/auth.test.ts | 23 +- .../tests/db/websocket/general.test.ts | 8 +- tests/blackbox/vitest.config.ts | 6 + 18 files changed, 349 insertions(+), 138 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd137fae2f651..443708ad1c242 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2138,8 +2138,8 @@ importers: specifier: 4.3.2 version: 4.3.2(typescript@5.4.5)(vite@5.2.11(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0)) vitest: - specifier: 1.5.3 - version: 1.5.3(@types/node@18.19.33)(happy-dom@14.12.0)(jsdom@24.0.0)(sass@1.77.5)(terser@5.31.0) + specifier: 1.6.0 + version: 1.6.0(@types/node@18.19.33)(happy-dom@14.12.0)(jsdom@24.0.0)(sass@1.77.5)(terser@5.31.0) ws: specifier: 8.17.0 version: 8.17.0 @@ -5001,18 +5001,33 @@ packages: '@vitest/expect@1.5.3': resolution: {integrity: sha512-y+waPz31pOFr3rD7vWTbwiLe5+MgsMm40jTZbQE8p8/qXyBX3CQsIXRx9XK12IbY7q/t5a5aM/ckt33b4PxK2g==} + '@vitest/expect@1.6.0': + resolution: {integrity: sha512-ixEvFVQjycy/oNgHjqsL6AZCDduC+tflRluaHIzKIsdbzkLn2U/iBnVeJwB6HsIjQBdfMR8Z0tRxKUsvFJEeWQ==} + '@vitest/runner@1.5.3': resolution: {integrity: sha512-7PlfuReN8692IKQIdCxwir1AOaP5THfNkp0Uc4BKr2na+9lALNit7ub9l3/R7MP8aV61+mHKRGiqEKRIwu6iiQ==} + '@vitest/runner@1.6.0': + resolution: {integrity: sha512-P4xgwPjwesuBiHisAVz/LSSZtDjOTPYZVmNAnpHHSR6ONrf8eCJOFRvUwdHn30F5M1fxhqtl7QZQUk2dprIXAg==} + '@vitest/snapshot@1.5.3': resolution: {integrity: sha512-K3mvIsjyKYBhNIDujMD2gfQEzddLe51nNOAf45yKRt/QFJcUIeTQd2trRvv6M6oCBHNVnZwFWbQ4yj96ibiDsA==} + '@vitest/snapshot@1.6.0': + resolution: {integrity: sha512-+Hx43f8Chus+DCmygqqfetcAZrDJwvTj0ymqjQq4CvmpKFSTVteEOBzCusu1x2tt4OJcvBflyHUE0DZSLgEMtQ==} + '@vitest/spy@1.5.3': resolution: {integrity: sha512-Llj7Jgs6lbnL55WoshJUUacdJfjU2honvGcAJBxhra5TPEzTJH8ZuhI3p/JwqqfnTr4PmP7nDmOXP53MS7GJlg==} + '@vitest/spy@1.6.0': + resolution: {integrity: sha512-leUTap6B/cqi/bQkXUu6bQV5TZPx7pmMBKBQiI0rJA8c3pB56ZsaTbREnF7CJfmvAS4V2cXIBAh/3rVwrrCYgw==} + '@vitest/utils@1.5.3': resolution: {integrity: sha512-rE9DTN1BRhzkzqNQO+kw8ZgfeEBCLXiHJwetk668shmNBpSagQxneT5eSqEBLP+cqSiAeecvQmbpFfdMyLcIQA==} + '@vitest/utils@1.6.0': + resolution: {integrity: sha512-21cPiuGMoMZwiOHa2i4LXkMkMkCGzA+MVFV70jRwHo95dL4x/ts5GZhML1QWuy7yfp3WzK3lRvZi3JnXTYqrBw==} + '@volar/language-core@1.11.1': resolution: {integrity: sha512-dOcNn3i9GgZAcJt43wuaEykSluAuOkQgzni1cuxLxTV0nJKanQztp7FxyswdRILaKH+P2XZMPRp2S4MV/pElCw==} @@ -11242,6 +11257,11 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true + vite-node@1.6.0: + resolution: {integrity: sha512-de6HJgzC+TFzOu0NTC4RAIsyf/DY/ibWDYQUcuEA84EMHhcefTUGkjFHKKEJhQN4A+6I0u++kr3l36ZF2d7XRw==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + vite-plugin-dts@3.9.1: resolution: {integrity: sha512-rVp2KM9Ue22NGWB8dNtWEr+KekN3rIgz1tWD050QnRGlriUCmaDwa7qA5zDEjbXg5lAXhYMSBJtx3q3hQIJZSg==} engines: {node: ^14.18.0 || >=16.0.0} @@ -11351,6 +11371,31 @@ packages: jsdom: optional: true + vitest@1.6.0: + resolution: {integrity: sha512-H5r/dN06swuFnzNFhq/dnz37bPXnq8xB2xB5JOVk8K09rUtoeNN+LHWkoQ0A/i3hvbUKKcCei9KpbxqHMLhLLA==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@types/node': ^18.0.0 || >=20.0.0 + '@vitest/browser': 1.6.0 + '@vitest/ui': 1.6.0 + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@types/node': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + vscode-oniguruma@1.7.0: resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==} @@ -11954,8 +11999,8 @@ snapshots: '@aws-crypto/sha1-browser': 3.0.0 '@aws-crypto/sha256-browser': 3.0.0 '@aws-crypto/sha256-js': 3.0.0 - '@aws-sdk/client-sso-oidc': 3.569.0 - '@aws-sdk/client-sts': 3.569.0(@aws-sdk/client-sso-oidc@3.569.0) + '@aws-sdk/client-sso-oidc': 3.569.0(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/client-sts': 3.569.0 '@aws-sdk/core': 3.567.0 '@aws-sdk/credential-provider-node': 3.569.0(@aws-sdk/client-sso-oidc@3.569.0)(@aws-sdk/client-sts@3.569.0) '@aws-sdk/middleware-bucket-endpoint': 3.568.0 @@ -12104,6 +12149,52 @@ snapshots: transitivePeerDependencies: - aws-crt + '@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0)': + dependencies: + '@aws-crypto/sha256-browser': 3.0.0 + '@aws-crypto/sha256-js': 3.0.0 + '@aws-sdk/client-sts': 3.569.0 + '@aws-sdk/core': 3.567.0 + '@aws-sdk/credential-provider-node': 3.569.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/middleware-host-header': 3.567.0 + '@aws-sdk/middleware-logger': 3.568.0 + '@aws-sdk/middleware-recursion-detection': 3.567.0 + '@aws-sdk/middleware-user-agent': 3.567.0 + '@aws-sdk/region-config-resolver': 3.567.0 + '@aws-sdk/types': 3.567.0 + '@aws-sdk/util-endpoints': 3.567.0 + '@aws-sdk/util-user-agent-browser': 3.567.0 + '@aws-sdk/util-user-agent-node': 3.568.0 + '@smithy/config-resolver': 2.2.0 + '@smithy/core': 1.4.2 + '@smithy/fetch-http-handler': 2.5.0 + '@smithy/hash-node': 2.2.0 + '@smithy/invalid-dependency': 2.2.0 + '@smithy/middleware-content-length': 2.2.0 + '@smithy/middleware-endpoint': 2.5.1 + '@smithy/middleware-retry': 2.3.1 + '@smithy/middleware-serde': 2.3.0 + '@smithy/middleware-stack': 2.2.0 + '@smithy/node-config-provider': 2.3.0 + '@smithy/node-http-handler': 2.5.0 + '@smithy/protocol-http': 3.3.0 + '@smithy/smithy-client': 2.5.1 + '@smithy/types': 2.12.0 + '@smithy/url-parser': 2.2.0 + '@smithy/util-base64': 2.3.0 + '@smithy/util-body-length-browser': 2.2.0 + '@smithy/util-body-length-node': 2.3.0 + '@smithy/util-defaults-mode-browser': 2.2.1 + '@smithy/util-defaults-mode-node': 2.3.1 + '@smithy/util-endpoints': 1.2.0 + '@smithy/util-middleware': 2.2.0 + '@smithy/util-retry': 2.2.0 + '@smithy/util-utf8': 2.3.0 + tslib: 2.6.2 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + '@aws-sdk/client-sso@3.568.0': dependencies: '@aws-crypto/sha256-browser': 3.0.0 @@ -12267,6 +12358,23 @@ snapshots: '@smithy/util-stream': 2.2.0 tslib: 2.6.2 + '@aws-sdk/credential-provider-ini@3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))(@aws-sdk/client-sts@3.569.0)': + dependencies: + '@aws-sdk/client-sts': 3.569.0 + '@aws-sdk/credential-provider-env': 3.568.0 + '@aws-sdk/credential-provider-process': 3.568.0 + '@aws-sdk/credential-provider-sso': 3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0)) + '@aws-sdk/credential-provider-web-identity': 3.568.0(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/types': 3.567.0 + '@smithy/credential-provider-imds': 2.3.0 + '@smithy/property-provider': 2.2.0 + '@smithy/shared-ini-file-loader': 2.4.0 + '@smithy/types': 2.12.0 + tslib: 2.6.2 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - aws-crt + '@aws-sdk/credential-provider-ini@3.568.0(@aws-sdk/client-sso-oidc@3.569.0)(@aws-sdk/client-sts@3.569.0(@aws-sdk/client-sso-oidc@3.569.0))': dependencies: '@aws-sdk/client-sts': 3.569.0(@aws-sdk/client-sso-oidc@3.569.0) @@ -12320,6 +12428,25 @@ snapshots: - '@aws-sdk/client-sts' - aws-crt + '@aws-sdk/credential-provider-node@3.569.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))(@aws-sdk/client-sts@3.569.0)': + dependencies: + '@aws-sdk/credential-provider-env': 3.568.0 + '@aws-sdk/credential-provider-http': 3.568.0 + '@aws-sdk/credential-provider-ini': 3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/credential-provider-process': 3.568.0 + '@aws-sdk/credential-provider-sso': 3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0)) + '@aws-sdk/credential-provider-web-identity': 3.568.0(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/types': 3.567.0 + '@smithy/credential-provider-imds': 2.3.0 + '@smithy/property-provider': 2.2.0 + '@smithy/shared-ini-file-loader': 2.4.0 + '@smithy/types': 2.12.0 + tslib: 2.6.2 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - '@aws-sdk/client-sts' + - aws-crt + '@aws-sdk/credential-provider-node@3.569.0(@aws-sdk/client-sso-oidc@3.569.0)(@aws-sdk/client-sts@3.569.0(@aws-sdk/client-sso-oidc@3.569.0))': dependencies: '@aws-sdk/credential-provider-env': 3.568.0 @@ -12366,6 +12493,19 @@ snapshots: '@smithy/types': 2.12.0 tslib: 2.6.2 + '@aws-sdk/credential-provider-sso@3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))': + dependencies: + '@aws-sdk/client-sso': 3.568.0 + '@aws-sdk/token-providers': 3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0)) + '@aws-sdk/types': 3.567.0 + '@smithy/property-provider': 2.2.0 + '@smithy/shared-ini-file-loader': 2.4.0 + '@smithy/types': 2.12.0 + tslib: 2.6.2 + transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' + - aws-crt + '@aws-sdk/credential-provider-sso@3.568.0(@aws-sdk/client-sso-oidc@3.569.0)': dependencies: '@aws-sdk/client-sso': 3.568.0 @@ -12514,6 +12654,15 @@ snapshots: '@smithy/types': 2.12.0 tslib: 2.6.2 + '@aws-sdk/token-providers@3.568.0(@aws-sdk/client-sso-oidc@3.569.0(@aws-sdk/client-sts@3.569.0))': + dependencies: + '@aws-sdk/client-sso-oidc': 3.569.0(@aws-sdk/client-sts@3.569.0) + '@aws-sdk/types': 3.567.0 + '@smithy/property-provider': 2.2.0 + '@smithy/shared-ini-file-loader': 2.4.0 + '@smithy/types': 2.12.0 + tslib: 2.6.2 + '@aws-sdk/token-providers@3.568.0(@aws-sdk/client-sso-oidc@3.569.0)': dependencies: '@aws-sdk/client-sso-oidc': 3.569.0 @@ -15461,22 +15610,44 @@ snapshots: '@vitest/utils': 1.5.3 chai: 4.4.1 + '@vitest/expect@1.6.0': + dependencies: + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 + chai: 4.4.1 + '@vitest/runner@1.5.3': dependencies: '@vitest/utils': 1.5.3 p-limit: 5.0.0 pathe: 1.1.2 + '@vitest/runner@1.6.0': + dependencies: + '@vitest/utils': 1.6.0 + p-limit: 5.0.0 + pathe: 1.1.2 + '@vitest/snapshot@1.5.3': dependencies: magic-string: 0.30.10 pathe: 1.1.2 pretty-format: 29.7.0 + '@vitest/snapshot@1.6.0': + dependencies: + magic-string: 0.30.10 + pathe: 1.1.2 + pretty-format: 29.7.0 + '@vitest/spy@1.5.3': dependencies: tinyspy: 2.2.1 + '@vitest/spy@1.6.0': + dependencies: + tinyspy: 2.2.1 + '@vitest/utils@1.5.3': dependencies: diff-sequences: 29.6.3 @@ -15484,6 +15655,13 @@ snapshots: loupe: 2.3.7 pretty-format: 29.7.0 + '@vitest/utils@1.6.0': + dependencies: + diff-sequences: 29.6.3 + estree-walker: 3.0.3 + loupe: 2.3.7 + pretty-format: 29.7.0 + '@volar/language-core@1.11.1': dependencies: '@volar/source-map': 1.11.1 @@ -22844,6 +23022,23 @@ snapshots: - supports-color - terser + vite-node@1.6.0(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0): + dependencies: + cac: 6.7.14 + debug: 4.3.4(supports-color@5.5.0) + pathe: 1.1.2 + picocolors: 1.0.0 + vite: 5.2.11(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0) + transitivePeerDependencies: + - '@types/node' + - less + - lightningcss + - sass + - stylus + - sugarss + - supports-color + - terser + vite-plugin-dts@3.9.1(@types/node@18.19.33)(rollup@4.17.2)(typescript@5.4.5)(vite@5.2.11(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0)): dependencies: '@microsoft/api-extractor': 7.43.0(@types/node@18.19.33) @@ -22976,6 +23171,41 @@ snapshots: - supports-color - terser + vitest@1.6.0(@types/node@18.19.33)(happy-dom@14.12.0)(jsdom@24.0.0)(sass@1.77.5)(terser@5.31.0): + dependencies: + '@vitest/expect': 1.6.0 + '@vitest/runner': 1.6.0 + '@vitest/snapshot': 1.6.0 + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 + acorn-walk: 8.3.2 + chai: 4.4.1 + debug: 4.3.4(supports-color@5.5.0) + execa: 8.0.1 + local-pkg: 0.5.0 + magic-string: 0.30.10 + pathe: 1.1.2 + picocolors: 1.0.0 + std-env: 3.7.0 + strip-literal: 2.1.0 + tinybench: 2.8.0 + tinypool: 0.8.4 + vite: 5.2.11(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0) + vite-node: 1.6.0(@types/node@18.19.33)(sass@1.77.5)(terser@5.31.0) + why-is-node-running: 2.2.2 + optionalDependencies: + '@types/node': 18.19.33 + happy-dom: 14.12.0 + jsdom: 24.0.0 + transitivePeerDependencies: + - less + - lightningcss + - sass + - stylus + - sugarss + - supports-color + - terser + vscode-oniguruma@1.7.0: {} vscode-textmate@8.0.0: {} diff --git a/tests/blackbox/common/functions.ts b/tests/blackbox/common/functions.ts index d832c5162a919..134b70c82e31e 100644 --- a/tests/blackbox/common/functions.ts +++ b/tests/blackbox/common/functions.ts @@ -27,7 +27,7 @@ export function ClearCaches() { // Assert const response = await request(getUrl(vendor)) - .post(`/utils/cache/clear`) + .post(`/utils/cache/clear?system`) .set('Authorization', `Bearer ${USER.TESTS_FLOW.TOKEN}`); const response2 = await request(getUrl(vendor)) diff --git a/tests/blackbox/package.json b/tests/blackbox/package.json index 7f3e3f2dc4ee1..7953a9f84a203 100644 --- a/tests/blackbox/package.json +++ b/tests/blackbox/package.json @@ -33,7 +33,7 @@ "typescript": "5.4.5", "uuid": "9.0.1", "vite-tsconfig-paths": "4.3.2", - "vitest": "1.5.3", + "vitest": "1.6.0", "ws": "8.17.0" } } diff --git a/tests/blackbox/setup/sequencer.ts b/tests/blackbox/setup/sequencer.ts index f441124e0e517..e93e380f96a7a 100644 --- a/tests/blackbox/setup/sequencer.ts +++ b/tests/blackbox/setup/sequencer.ts @@ -23,6 +23,8 @@ export default class CustomSequencer extends BaseSequencer { if (test) { onlyTests.push(test); } + } else { + throw new Error(`Non-existent test file "${sequentialTest}" in "only" list`); } } @@ -39,6 +41,8 @@ export default class CustomSequencer extends BaseSequencer { if (test) { files.unshift(test); } + } else { + throw new Error(`Non-existent test file "${sequentialTest}" in "before" list`); } } @@ -53,6 +57,8 @@ export default class CustomSequencer extends BaseSequencer { if (test) { files.push(test); } + } else { + throw new Error(`Non-existent test file "${sequentialTest}" in "after" list`); } } } diff --git a/tests/blackbox/setup/sequential-tests.ts b/tests/blackbox/setup/sequential-tests.ts index 64db56b965ece..7409c03d23bf2 100644 --- a/tests/blackbox/setup/sequential-tests.ts +++ b/tests/blackbox/setup/sequential-tests.ts @@ -27,7 +27,6 @@ export const sequentialTestsList: Record<'db' | 'common', SequentialTestsList> = '/tests/db/routes/flows/webhook.test.ts', '/tests/db/app/cache.test.ts', '/tests/db/routes/collections/schema-cache.test.ts', - '/tests/db/routes/assets/concurrency.test.ts', ], // If specified, only run these tests sequentially only: [ diff --git a/tests/blackbox/tests/common/assets/read.test.ts b/tests/blackbox/tests/common/assets/read.test.ts index 792a2b2c9ffed..30bdad9d89dde 100644 --- a/tests/blackbox/tests/common/assets/read.test.ts +++ b/tests/blackbox/tests/common/assets/read.test.ts @@ -21,37 +21,25 @@ const imageFilePath = join(...assetsDirectory, imageFile.name); describe('/assets', () => { describe('GET /assets/:id', () => { describe.each(storages)('Storage: %s', (storage) => { - it.each(vendors)( - '%s', - async (vendor) => { - // Setup - const insertResponse = await request(getUrl(vendor)) - .post('/files') - .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) - .field('storage', storage) - .attach('file', createReadStream(imageFilePath)); + it.each(vendors)('%s', async (vendor) => { + // Setup + const insertResponse = await request(getUrl(vendor)) + .post('/files') + .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) + .field('storage', storage) + .attach('file', createReadStream(imageFilePath)); - // TODO temporarily in place to find cause of flaky test - if (!insertResponse.body?.data?.id) { - /* eslint-disable no-console */ - console.log(insertResponse.statusCode); - console.log(insertResponse.body); - /* eslint-enable no-console */ - } + // Action + const response = await request(getUrl(vendor)) + .get(`/assets/${insertResponse.body.data.id}`) + .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`); - // Action - const response = await request(getUrl(vendor)) - .get(`/assets/${insertResponse.body.data.id}`) - .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`); - - // Assert - expect(response.statusCode).toBe(200); - expect(response.headers['content-type']).toBe(imageFile.type); - expect(response.headers['content-length']).toBe(imageFile.filesize); - expect(Buffer.compare(response.body, await readFile(imageFilePath))).toBe(0); - }, - { retry: 1 }, - ); + // Assert + expect(response.statusCode).toBe(200); + expect(response.headers['content-type']).toBe(imageFile.type); + expect(response.headers['content-length']).toBe(imageFile.filesize); + expect(Buffer.compare(response.body, await readFile(imageFilePath))).toBe(0); + }); }); }); }); diff --git a/tests/blackbox/tests/common/flows/schedule-hook.test.ts b/tests/blackbox/tests/common/flows/schedule-hook.test.ts index 8f1dcbc360bd0..883172453f9e2 100644 --- a/tests/blackbox/tests/common/flows/schedule-hook.test.ts +++ b/tests/blackbox/tests/common/flows/schedule-hook.test.ts @@ -4,6 +4,7 @@ import { USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { delayedSleep } from '@utils/sleep'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; @@ -48,13 +49,13 @@ describe('Flows Schedule Hook Tests', () => { delete envMemory[vendor]['SYNCHRONIZATION_STORE']; envMemory[vendor][envTargetVariable] = 'memory-1'; - const newServerPort1 = Number(envRedis1[vendor]!.PORT) + 150; - const newServerPort2 = Number(envRedis2[vendor]!.PORT) + 200; - const newServerPort3 = Number(envMemory[vendor]!.PORT) + 250; + const newServerPort1 = await getPort(); + const newServerPort2 = await getPort(); + const newServerPort3 = await getPort(); - envRedis1[vendor]!.PORT = String(newServerPort1); - envRedis2[vendor]!.PORT = String(newServerPort2); - envMemory[vendor]!.PORT = String(newServerPort3); + envRedis1[vendor].PORT = String(newServerPort1); + envRedis2[vendor].PORT = String(newServerPort2); + envMemory[vendor].PORT = String(newServerPort3); const server1 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: envRedis1[vendor] }); const server2 = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: envRedis2[vendor] }); @@ -63,9 +64,11 @@ describe('Flows Schedule Hook Tests', () => { directusInstances[vendor] = [server1, server2, server3]; envs[vendor] = [envRedis1, envRedis2, envMemory]; - promises.push(awaitDirectusConnection(newServerPort1)); - promises.push(awaitDirectusConnection(newServerPort2)); - promises.push(awaitDirectusConnection(newServerPort3)); + promises.push( + awaitDirectusConnection(newServerPort1), + awaitDirectusConnection(newServerPort2), + awaitDirectusConnection(newServerPort3), + ); } // Give the server some time to start diff --git a/tests/blackbox/tests/common/logger/redact.test.ts b/tests/blackbox/tests/common/logger/redact.test.ts index 6f43a0a795302..5b6cbbe507ae2 100644 --- a/tests/blackbox/tests/common/logger/redact.test.ts +++ b/tests/blackbox/tests/common/logger/redact.test.ts @@ -5,34 +5,35 @@ import { requestGraphQL } from '@common/transport'; import { TEST_USERS, USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import { EnumType } from 'json-to-graphql-query'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; import request from 'supertest'; -import { beforeAll, afterAll, expect, describe, it } from 'vitest'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; describe('Logger Redact Tests', () => { const databases = new Map(); const directusInstances = {} as Record; const env = cloneDeep(config.envs); - for (const vendor of vendors) { - env[vendor]['LOG_STYLE'] = 'raw'; - env[vendor]['LOG_LEVEL'] = 'info'; - env[vendor].PORT = String(Number(env[vendor].PORT) + 500); - } - beforeAll(async () => { const promises = []; for (const vendor of vendors) { databases.set(vendor, knex(config.knexConfig[vendor]!)); + const newServerPort = await getPort(); + + env[vendor]['LOG_STYLE'] = 'raw'; + env[vendor]['LOG_LEVEL'] = 'info'; + env[vendor].PORT = String(newServerPort); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); directusInstances[vendor] = server; - promises.push(awaitDirectusConnection(Number(env[vendor].PORT))); + promises.push(awaitDirectusConnection(newServerPort)); } // Give the server some time to start diff --git a/tests/blackbox/tests/db/app/cache.test.ts b/tests/blackbox/tests/db/app/cache.test.ts index 41ce03795894c..7b5d77f28ad7a 100644 --- a/tests/blackbox/tests/db/app/cache.test.ts +++ b/tests/blackbox/tests/db/app/cache.test.ts @@ -3,6 +3,7 @@ import vendors, { type Vendor } from '@common/get-dbs-to-test'; import { USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; @@ -60,10 +61,10 @@ describe('App Caching Tests', () => { envRedisPurge[vendor]['CACHE_AUTO_PURGE'] = 'true'; envRedisPurge[vendor]['CACHE_NAMESPACE'] = `${cacheNamespacePrefix}_redis_purge`; - const newServerPortMem = Number(envMem[vendor].PORT) + 150; - const newServerPortMemPurge = Number(envMemPurge[vendor].PORT) + 200; - const newServerPortRedis = Number(envRedis[vendor].PORT) + 250; - const newServerPortRedisPurge = Number(envRedisPurge[vendor].PORT) + 300; + const newServerPortMem = await getPort(); + const newServerPortMemPurge = await getPort(); + const newServerPortRedis = await getPort(); + const newServerPortRedisPurge = await getPort(); envMem[vendor].PORT = String(newServerPortMem); envMemPurge[vendor].PORT = String(newServerPortMemPurge); @@ -78,10 +79,12 @@ describe('App Caching Tests', () => { directusInstances[vendor] = [serverMem, serverMemPurge, serverRedis, serverRedisPurge]; envs[vendor] = { envMem, envMemPurge, envRedis, envRedisPurge }; - promises.push(awaitDirectusConnection(newServerPortMem)); - promises.push(awaitDirectusConnection(newServerPortMemPurge)); - promises.push(awaitDirectusConnection(newServerPortRedis)); - promises.push(awaitDirectusConnection(newServerPortRedisPurge)); + promises.push( + awaitDirectusConnection(newServerPortMem), + awaitDirectusConnection(newServerPortMemPurge), + awaitDirectusConnection(newServerPortRedis), + awaitDirectusConnection(newServerPortRedisPurge), + ); } // Give the server some time to start diff --git a/tests/blackbox/tests/db/routes/collections/schema-cache.test.ts b/tests/blackbox/tests/db/routes/collections/schema-cache.test.ts index 081da6c3ab96a..b2f21f180d231 100644 --- a/tests/blackbox/tests/db/routes/collections/schema-cache.test.ts +++ b/tests/blackbox/tests/db/routes/collections/schema-cache.test.ts @@ -4,12 +4,12 @@ import vendors, { type Vendor } from '@common/get-dbs-to-test'; import { USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; import request from 'supertest'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import getPort from 'get-port'; const newCollectionName = 'schema-caching-test'; @@ -49,8 +49,7 @@ describe('Schema Caching Tests', () => { tzDirectus[vendor] = [server1, server2]; envs[vendor] = [env1, env2]; - promises.push(awaitDirectusConnection(newServerPort1)); - promises.push(awaitDirectusConnection(newServerPort2)); + promises.push(awaitDirectusConnection(newServerPort1), awaitDirectusConnection(newServerPort2)); } // Give the server some time to start @@ -150,8 +149,7 @@ describe('Schema Caching Tests', () => { tzDirectus[vendor] = [server3, server4]; envs[vendor] = [env3, env4]; - promises.push(awaitDirectusConnection(newServerPort3)); - promises.push(awaitDirectusConnection(newServerPort4)); + promises.push(awaitDirectusConnection(newServerPort3), awaitDirectusConnection(newServerPort4)); } // Give the server some time to start diff --git a/tests/blackbox/tests/db/routes/flows/webhook.test.ts b/tests/blackbox/tests/db/routes/flows/webhook.test.ts index f47f20c7328f2..ce098dbe8a17a 100644 --- a/tests/blackbox/tests/db/routes/flows/webhook.test.ts +++ b/tests/blackbox/tests/db/routes/flows/webhook.test.ts @@ -4,6 +4,7 @@ import { USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; @@ -25,8 +26,8 @@ describe('/flows', () => { env[vendor]['CACHE_ENABLED'] = 'true'; env[vendor]['CACHE_STORE'] = 'memory'; - const newServerPort = Number(env[vendor]!.PORT) + 150; - env[vendor]!.PORT = String(newServerPort); + const newServerPort = await getPort(); + env[vendor].PORT = String(newServerPort); const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); @@ -38,7 +39,7 @@ describe('/flows', () => { // Give the server some time to start await Promise.all(promises); - }, 180000); + }, 180_000); afterAll(async () => { for (const [vendor, connection] of databases) { diff --git a/tests/blackbox/tests/db/routes/permissions/cache-purge.test.ts b/tests/blackbox/tests/db/routes/permissions/cache-purge.test.ts index 9dc5196ebb4f6..34f1e3db76769 100644 --- a/tests/blackbox/tests/db/routes/permissions/cache-purge.test.ts +++ b/tests/blackbox/tests/db/routes/permissions/cache-purge.test.ts @@ -3,11 +3,11 @@ import vendors, { type Vendor } from '@common/get-dbs-to-test'; import { USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import { cloneDeep } from 'lodash-es'; import request from 'supertest'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { collection, type Collection } from './cache-purge.seed'; -import getPort from 'get-port'; describe('Permissions Cache Purging Tests', () => { const cacheStatusHeader = 'x-cache-status'; @@ -183,7 +183,7 @@ describe('Permissions Cache Purging Tests', () => { await awaitDirectusConnection(newServerPort); }, 60_000); - afterAll(async () => { + afterAll(() => { instance.kill(); }); diff --git a/tests/blackbox/tests/db/routes/server/health.test.ts b/tests/blackbox/tests/db/routes/server/health.test.ts index 1fba968e03b3b..c00d5ed470b85 100644 --- a/tests/blackbox/tests/db/routes/server/health.test.ts +++ b/tests/blackbox/tests/db/routes/server/health.test.ts @@ -21,17 +21,6 @@ describe('/server', () => { }, }); - // TODO temporarily in place to find cause of flaky test - if (response.body?.status !== 'ok') { - // eslint-disable-next-line no-console - console.log(response.body); - } - - if (gqlResponse.body?.data?.server_health?.status !== 'ok') { - // eslint-disable-next-line no-console - console.log(gqlResponse.body); - } - // Assert expect(response.statusCode).toBe(200); expect(gqlResponse.statusCode).toBe(200); diff --git a/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-america.test.ts b/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-america.test.ts index 99803b5cb3ce5..f0324e8067a41 100644 --- a/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-america.test.ts +++ b/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-america.test.ts @@ -5,6 +5,7 @@ import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; import { validateDateDifference } from '@utils/validate-date-difference'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; @@ -28,6 +29,7 @@ type SchemaTimezoneTypesResponse = SchemaTimezoneTypesObject & { describe('schema', () => { const databases = new Map(); const tzDirectus = {} as Record; + const env = cloneDeep(config.envs); const currentTzOffset = new Date().getTimezoneOffset(); const isWindows = ['win32', 'win64'].includes(process.platform); const newTzOffset = currentTzOffset !== 180 ? 180 : 360; @@ -73,21 +75,15 @@ describe('schema', () => { const promises = []; for (const vendor of vendors) { - const newServerPort = Number(config.envs[vendor]!.PORT) + 100; databases.set(vendor, knex(config.knexConfig[vendor]!)); - config.envs[vendor]['TZ'] = newTz; - config.envs[vendor].PORT = String(newServerPort); + const newServerPort = await getPort(); - const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: config.envs[vendor] }); - tzDirectus[vendor] = server; - - let serverOutput = ''; - server.stdout.on('data', (data) => (serverOutput += data.toString())); + env[vendor]['TZ'] = newTz; + env[vendor].PORT = String(newServerPort); - server.on('exit', (code) => { - if (code !== null) throw new Error(`Directus-${vendor} server failed (${code}): \n ${serverOutput}`); - }); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); + tzDirectus[vendor] = server; promises.push(awaitDirectusConnection(newServerPort)); } @@ -100,9 +96,6 @@ describe('schema', () => { for (const [vendor, connection] of databases) { tzDirectus[vendor].kill(); - config.envs[vendor].PORT = String(Number(config.envs[vendor]!.PORT) - 100); - delete config.envs[vendor]['TZ']; - await connection.destroy(); } }); @@ -112,7 +105,7 @@ describe('schema', () => { it.each(vendors)('%s', async (vendor) => { const currentTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -196,7 +189,7 @@ describe('schema', () => { const insertionStartTimestamp = new Date(); - await request(getUrl(vendor)) + await request(getUrl(vendor, env)) .post(`/items/${collectionName}`) .send(dates) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) @@ -205,7 +198,7 @@ describe('schema', () => { const insertionEndTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&offset=${sampleDates.length}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -271,7 +264,7 @@ describe('schema', () => { date: sampleDates[0]!.date, }; - const existingDataResponse = await request(getUrl(vendor)) + const existingDataResponse = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&limit=1&offset=${sampleDates.length}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -279,7 +272,7 @@ describe('schema', () => { const updateStartTimestamp = new Date(); - await request(getUrl(vendor)) + await request(getUrl(vendor, env)) .patch(`/items/${collectionName}/${existingDataResponse.body.data[0].id}`) .send(payload) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) @@ -288,7 +281,7 @@ describe('schema', () => { const updateEndTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}/${existingDataResponse.body.data[0].id}?fields=*`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) diff --git a/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-asia.test.ts b/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-asia.test.ts index 9844095e47e49..f41edd7a84eca 100644 --- a/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-asia.test.ts +++ b/tests/blackbox/tests/db/schema/timezone/timezone-changed-node-tz-asia.test.ts @@ -5,6 +5,7 @@ import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; import { validateDateDifference } from '@utils/validate-date-difference'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import type { Knex } from 'knex'; import knex from 'knex'; import { cloneDeep } from 'lodash-es'; @@ -28,6 +29,7 @@ type SchemaTimezoneTypesResponse = SchemaTimezoneTypesObject & { describe('schema', () => { const databases = new Map(); const tzDirectus = {} as Record; + const env = cloneDeep(config.envs); const currentTzOffset = new Date().getTimezoneOffset(); const isWindows = ['win32', 'win64'].includes(process.platform); @@ -74,21 +76,15 @@ describe('schema', () => { const promises = []; for (const vendor of vendors) { - const newServerPort = Number(config.envs[vendor]!.PORT) + 100; databases.set(vendor, knex(config.knexConfig[vendor]!)); - config.envs[vendor]['TZ'] = newTz; - config.envs[vendor].PORT = String(newServerPort); + const newServerPort = await getPort(); - const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: config.envs[vendor] }); - tzDirectus[vendor] = server; - - let serverOutput = ''; - server.stdout.on('data', (data) => (serverOutput += data.toString())); + env[vendor]['TZ'] = newTz; + env[vendor].PORT = String(newServerPort); - server.on('exit', (code) => { - if (code !== null) throw new Error(`Directus-${vendor} server failed (${code}): \n ${serverOutput}`); - }); + const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); + tzDirectus[vendor] = server; promises.push(awaitDirectusConnection(newServerPort)); } @@ -101,9 +97,6 @@ describe('schema', () => { for (const [vendor, connection] of databases) { tzDirectus[vendor].kill(); - config.envs[vendor].PORT = String(Number(config.envs[vendor].PORT) - 100); - delete config.envs[vendor]['TZ']; - await connection.destroy(); } }); @@ -113,7 +106,7 @@ describe('schema', () => { it.each(vendors)('%s', async (vendor) => { const currentTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&limit=${sampleDates.length}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -183,7 +176,7 @@ describe('schema', () => { const americanTzOffset = currentTzOffset !== 180 ? 180 : 360; - const response2 = await request(getUrl(vendor)) + const response2 = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&offset=${sampleDates.length}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -269,7 +262,7 @@ describe('schema', () => { const insertionStartTimestamp = new Date(); - await request(getUrl(vendor)) + await request(getUrl(vendor, env)) .post(`/items/${collectionName}`) .send(dates) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) @@ -278,7 +271,7 @@ describe('schema', () => { const insertionEndTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&offset=${sampleDates.length * 2}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -344,7 +337,7 @@ describe('schema', () => { date: sampleDates[0]!.date, }; - const existingDataResponse = await request(getUrl(vendor)) + const existingDataResponse = await request(getUrl(vendor, env)) .get(`/items/${collectionName}?fields=*&limit=1&offset=${sampleDates.length * 2}`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) @@ -352,7 +345,7 @@ describe('schema', () => { const updateStartTimestamp = new Date(); - await request(getUrl(vendor)) + await request(getUrl(vendor, env)) .patch(`/items/${collectionName}/${existingDataResponse.body.data[0].id}`) .send(payload) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) @@ -361,7 +354,7 @@ describe('schema', () => { const updateEndTimestamp = new Date(); - const response = await request(getUrl(vendor)) + const response = await request(getUrl(vendor, env)) .get(`/items/${collectionName}/${existingDataResponse.body.data[0].id}?fields=*`) .set('Authorization', `Bearer ${USER.ADMIN.TOKEN}`) .expect('Content-Type', /application\/json/) diff --git a/tests/blackbox/tests/db/websocket/auth.test.ts b/tests/blackbox/tests/db/websocket/auth.test.ts index 458e3a5a2c1b8..1803d4a4dab55 100644 --- a/tests/blackbox/tests/db/websocket/auth.test.ts +++ b/tests/blackbox/tests/db/websocket/auth.test.ts @@ -6,6 +6,7 @@ import { TEST_USERS, USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import knex, { Knex } from 'knex'; import { cloneDeep } from 'lodash-es'; import request from 'supertest'; @@ -22,32 +23,32 @@ describe('WebSocket Auth Tests', () => { const directusInstances = {} as { [vendor: string]: ChildProcess }; const env = cloneDeep(config.envs); - for (const vendor of vendors) { - env[vendor]['WEBSOCKETS_REST_AUTH'] = authMethod; - env[vendor]['WEBSOCKETS_REST_AUTH_TIMEOUT'] = String(authenticationTimeoutSeconds); - env[vendor]['WEBSOCKETS_REST_PATH'] = `/${pathREST}`; - env[vendor].PORT = String(Number(env[vendor].PORT) + 500); - } - beforeAll(async () => { const promises = []; for (const vendor of vendors) { - databases.set(vendor, knex(config.knexConfig[vendor]!)); + databases.set(vendor, knex(config.knexConfig[vendor])); + + const newServerPort = await getPort(); + + env[vendor]['WEBSOCKETS_REST_AUTH'] = authMethod; + env[vendor]['WEBSOCKETS_REST_AUTH_TIMEOUT'] = String(authenticationTimeoutSeconds); + env[vendor]['WEBSOCKETS_REST_PATH'] = `/${pathREST}`; + env[vendor].PORT = String(newServerPort); const server = spawn('node', [paths.cli, 'start'], { cwd: paths.cwd, env: env[vendor] }); directusInstances[vendor] = server; - promises.push(awaitDirectusConnection(Number(env[vendor].PORT))); + promises.push(awaitDirectusConnection(newServerPort)); } // Give the server some time to start await Promise.all(promises); - }, 180000); + }, 180_000); afterAll(async () => { for (const [vendor, connection] of databases) { - directusInstances[vendor]!.kill(); + directusInstances[vendor]?.kill(); await connection.destroy(); } diff --git a/tests/blackbox/tests/db/websocket/general.test.ts b/tests/blackbox/tests/db/websocket/general.test.ts index 926c3ec4c45cc..db9b82df39a92 100644 --- a/tests/blackbox/tests/db/websocket/general.test.ts +++ b/tests/blackbox/tests/db/websocket/general.test.ts @@ -6,6 +6,7 @@ import { PRIMARY_KEY_TYPES, USER } from '@common/variables'; import { awaitDirectusConnection } from '@utils/await-connection'; import { sleep } from '@utils/sleep'; import { ChildProcess, spawn } from 'child_process'; +import getPort from 'get-port'; import knex, { Knex } from 'knex'; import { cloneDeep } from 'lodash-es'; import { randomUUID } from 'node:crypto'; @@ -29,8 +30,8 @@ describe('WebSocket General Tests', () => { const env2 = cloneDeep(env1); - const newServerPort1 = Number(env1[vendor]!.PORT) + 250; - const newServerPort2 = Number(env2[vendor]!.PORT) + 300; + const newServerPort1 = await getPort(); + const newServerPort2 = await getPort(); env1[vendor].PORT = String(newServerPort1); env2[vendor].PORT = String(newServerPort2); @@ -41,8 +42,7 @@ describe('WebSocket General Tests', () => { directusInstances[vendor] = [server1, server2]; envs[vendor] = [env1, env2]; - promises.push(awaitDirectusConnection(newServerPort1)); - promises.push(awaitDirectusConnection(newServerPort2)); + promises.push(awaitDirectusConnection(newServerPort1), awaitDirectusConnection(newServerPort2)); } // Give the server some time to start diff --git a/tests/blackbox/vitest.config.ts b/tests/blackbox/vitest.config.ts index 8b00f2f74cf5f..c21964bd1476b 100644 --- a/tests/blackbox/vitest.config.ts +++ b/tests/blackbox/vitest.config.ts @@ -6,6 +6,12 @@ export default defineConfig({ plugins: [tsconfigPaths()], test: { pool: 'forks', + poolOptions: { + forks: { + minForks: 1, + maxForks: 6, + }, + }, environment: './setup/environment.ts', sequence: { sequencer: Sequencer,