Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
ab799e13
authored
Apr 16, 2025
by
Finley Ge
Committed by
GitHub
Apr 16, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: concurrent test (#4548)
parent
ba422b73
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
test/setup.ts
+11
-6
vitest.config.mts
+2
-1
No files found.
test/setup.ts
View file @
ab799e13
...
@@ -2,11 +2,12 @@ import './mocks';
...
@@ -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
...
@@ -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 () => {
...
@@ -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
()
]);
});
});
});
vitest.config.mts
View file @
ab799e13
...
@@ -12,7 +12,8 @@ export default defineConfig({
...
@@ -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,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment