mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-16 16:04:34 +00:00
test: concurrent test (#4548)
This commit is contained in:
@@ -2,11 +2,12 @@ import './mocks';
|
|||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'fs';
|
||||||
import { connectMongo } from '@fastgpt/service/common/mongo/init';
|
import { connectMongo } from '@fastgpt/service/common/mongo/init';
|
||||||
import { initGlobalVariables } from '@/service/common/system';
|
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 setupModels from './setupModels';
|
||||||
import { clean } from './datas/users';
|
import { clean } from './datas/users';
|
||||||
import { connectionLogMongo, connectionMongo, Mongoose } from '@fastgpt/service/common/mongo';
|
import { connectionLogMongo, connectionMongo, Mongoose } from '@fastgpt/service/common/mongo';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
import { delay } from '@fastgpt/global/common/system/utils';
|
||||||
|
|
||||||
vi.stubEnv('NODE_ENV', 'test');
|
vi.stubEnv('NODE_ENV', 'test');
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ vi.mock(import('@fastgpt/service/common/mongo/init'), async (importOriginal: any
|
|||||||
return {
|
return {
|
||||||
...mod,
|
...mod,
|
||||||
connectMongo: async (db: Mongoose, url: string) => {
|
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(connectionMongo, inject('MONGODB_URI'));
|
||||||
await connectMongo(connectionLogMongo, inject('MONGODB_URI'));
|
await connectMongo(connectionLogMongo, inject('MONGODB_URI'));
|
||||||
|
|
||||||
return async () => {
|
onTestFinished(async () => {
|
||||||
clean();
|
clean();
|
||||||
await connectionMongo?.connection.db?.dropDatabase();
|
await delay(200); // wait for asynchronous operations to complete
|
||||||
await connectionLogMongo?.connection.db?.dropDatabase();
|
await Promise.all([
|
||||||
};
|
connectionMongo?.connection.db?.dropDatabase(),
|
||||||
|
connectionLogMongo?.connection.db?.dropDatabase()
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -12,7 +12,8 @@ export default defineConfig({
|
|||||||
outputFile: 'test-results.json',
|
outputFile: 'test-results.json',
|
||||||
setupFiles: 'test/setup.ts',
|
setupFiles: 'test/setup.ts',
|
||||||
globalSetup: 'test/globalSetup.ts',
|
globalSetup: 'test/globalSetup.ts',
|
||||||
fileParallelism: false,
|
// fileParallelism: false,
|
||||||
|
maxConcurrency: 5,
|
||||||
pool: 'threads',
|
pool: 'threads',
|
||||||
include: ['test/test.ts', 'test/cases/**/*.test.ts', 'projects/app/test/**/*.test.ts'],
|
include: ['test/test.ts', 'test/cases/**/*.test.ts', 'projects/app/test/**/*.test.ts'],
|
||||||
testTimeout: 5000,
|
testTimeout: 5000,
|
||||||
|
Reference in New Issue
Block a user