mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
test: concurrent test (#4548)
Some checks are pending
Deploy doc image to cf / deploy-production (push) Waiting to run
Deploy doc image by kubeconfig / build-fastgpt-docs-images (push) Waiting to run
Deploy doc image by kubeconfig / update-docs-image (push) Blocked by required conditions
Sync images / sync (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (push) Waiting to run
Some checks are pending
Deploy doc image to cf / deploy-production (push) Waiting to run
Deploy doc image by kubeconfig / build-fastgpt-docs-images (push) Waiting to run
Deploy doc image by kubeconfig / update-docs-image (push) Blocked by required conditions
Sync images / sync (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (push) Waiting to run
This commit is contained in:
parent
ba422b73b3
commit
ab799e13cd
|
|
@ -2,11 +2,12 @@ import './mocks';
|
|||
import { existsSync, readFileSync } from 'fs';
|
||||
import { connectMongo } from '@fastgpt/service/common/mongo/init';
|
||||
import { initGlobalVariables } from '@/service/common/system';
|
||||
import { afterAll, beforeAll, beforeEach, inject, vi } from 'vitest';
|
||||
import { afterAll, beforeAll, beforeEach, inject, onTestFinished, vi } from 'vitest';
|
||||
import setupModels from './setupModels';
|
||||
import { clean } from './datas/users';
|
||||
import { connectionLogMongo, connectionMongo, Mongoose } from '@fastgpt/service/common/mongo';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { delay } from '@fastgpt/global/common/system/utils';
|
||||
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
|
||||
|
|
@ -15,7 +16,8 @@ vi.mock(import('@fastgpt/service/common/mongo/init'), async (importOriginal: any
|
|||
return {
|
||||
...mod,
|
||||
connectMongo: async (db: Mongoose, url: string) => {
|
||||
(await db.connect(url)).connection.useDb(randomUUID());
|
||||
await db.connect(url, { dbName: randomUUID() });
|
||||
await db.connection.db?.dropDatabase();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -86,9 +88,12 @@ beforeEach(async () => {
|
|||
await connectMongo(connectionMongo, inject('MONGODB_URI'));
|
||||
await connectMongo(connectionLogMongo, inject('MONGODB_URI'));
|
||||
|
||||
return async () => {
|
||||
onTestFinished(async () => {
|
||||
clean();
|
||||
await connectionMongo?.connection.db?.dropDatabase();
|
||||
await connectionLogMongo?.connection.db?.dropDatabase();
|
||||
};
|
||||
await delay(200); // wait for asynchronous operations to complete
|
||||
await Promise.all([
|
||||
connectionMongo?.connection.db?.dropDatabase(),
|
||||
connectionLogMongo?.connection.db?.dropDatabase()
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ export default defineConfig({
|
|||
outputFile: 'test-results.json',
|
||||
setupFiles: 'test/setup.ts',
|
||||
globalSetup: 'test/globalSetup.ts',
|
||||
fileParallelism: false,
|
||||
// fileParallelism: false,
|
||||
maxConcurrency: 5,
|
||||
pool: 'threads',
|
||||
include: ['test/test.ts', 'test/cases/**/*.test.ts', 'projects/app/test/**/*.test.ts'],
|
||||
testTimeout: 5000,
|
||||
|
|
|
|||
Loading…
Reference in New Issue