fix(plugin-workflow-request): fix ignoreFail in sync mode (#4334)

* fix(plugin-workflow-request): fix ignoreFail in sync mode

* test(plugin-workflow-request): remote sleep in sync test
This commit is contained in:
Junyi 2024-05-13 23:01:01 +08:00 committed by GitHub
parent 6f4c884799
commit 145577942f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 9 deletions

View File

@ -83,7 +83,7 @@ export default class extends Instruction {
};
} catch (error) {
return {
status: JOB_STATUS.FAILED,
status: config.ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.FAILED,
result: error.isAxiosError ? error.toJSON() : error.message,
};
}

View File

@ -22,12 +22,6 @@ import { RequestConfig } from '../RequestInstruction';
const HOST = 'localhost';
function getRandomPort() {
const minPort = 1024;
const maxPort = 49151;
return Math.floor(Math.random() * (maxPort - minPort + 1)) + minPort;
}
class MockAPI {
app: Koa;
server: Server;
@ -38,6 +32,9 @@ class MockAPI {
get URL_400() {
return `http://${HOST}:${this.port}/api/400`;
}
get URL_404() {
return `http://${HOST}:${this.port}/api/404`;
}
get URL_TIMEOUT() {
return `http://${HOST}:${this.port}/api/timeout`;
}
@ -408,11 +405,16 @@ describe('workflow > instructions > request', () => {
});
describe('sync request', () => {
it('sync trigger', async () => {
const syncFlow = await WorkflowModel.create({
let syncFlow;
beforeEach(async () => {
syncFlow = await WorkflowModel.create({
type: 'syncTrigger',
enabled: true,
});
});
it('sync trigger', async () => {
await syncFlow.createNode({
type: 'request',
config: {
@ -432,5 +434,24 @@ describe('workflow > instructions > request', () => {
expect(job.status).toEqual(JOB_STATUS.RESOLVED);
expect(job.result).toEqual({ meta: {}, data: {} });
});
it('ignoreFail', async () => {
await syncFlow.createNode({
type: 'request',
config: {
url: api.URL_404,
method: 'GET',
ignoreFail: true,
} as RequestConfig,
});
const workflowPlugin = app.pm.get(PluginWorkflow) as PluginWorkflow;
const processor = (await workflowPlugin.trigger(syncFlow, { data: { title: 't1' } })) as Processor;
const [execution] = await syncFlow.getExecutions();
const [job] = await execution.getJobs();
expect(job.status).toBe(JOB_STATUS.RESOLVED);
expect(job.result.status).toBe(404);
});
});
});