Skip to content

Commit bbe5337

Browse files
authored
Merge pull request #548 from fractal-analytics-platform/wft-error-before-exec
Displayed an error when job submission failed before starting execution of tasks
2 parents e623641 + e915aca commit bbe5337

File tree

4 files changed

+109
-17
lines changed

4 files changed

+109
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Displayed an error when job submission failed before starting execution of tasks (\#548);
6+
37
# 1.4.3
48

59
* Added settings page to admin area (\#544);

__tests__/v2/workflow_page.test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { describe, it, beforeEach, expect, vi } from 'vitest';
2+
import { render } from '@testing-library/svelte';
3+
import { readable } from 'svelte/store';
4+
5+
// Mocking fetch
6+
global.fetch = vi.fn();
7+
8+
// Mocking the page store
9+
vi.mock('$app/stores', () => {
10+
return {
11+
page: readable({
12+
data: {
13+
workflow: {
14+
id: 1,
15+
name: 'test',
16+
project_id: 1,
17+
task_list: [{ id: 1, workflow_id: 1, task_id: 1, task: { id: 1, name: 'test' } }],
18+
project: { id: 1, name: 'test' }
19+
},
20+
datasets: [{ id: 1, name: 'test' }],
21+
defaultDatasetId: 1,
22+
userInfo: { id: 1, slurm_accounts: [] }
23+
},
24+
params: { projectId: 1 }
25+
})
26+
};
27+
});
28+
29+
// Mocking public variables
30+
vi.mock('$env/dynamic/public', () => {
31+
return { env: {} };
32+
});
33+
34+
// The component to be tested must be imported after the mock setup
35+
import page from '../../src/routes/v2/projects/[projectId]/workflows/[workflowId]/+page.svelte';
36+
37+
describe('Workflow page', () => {
38+
beforeEach(() => {
39+
fetch.mockClear();
40+
});
41+
42+
it('Display error when submission failed before starting execution of tasks', async () => {
43+
fetch.mockImplementation((url) => {
44+
return Promise.resolve({
45+
ok: true,
46+
status: 200,
47+
json: async () => {
48+
switch (url) {
49+
case '/api/v2/task':
50+
return [{ id: 1, workflow_id: 1, task_id: 1, task: { id: 1, name: 'test' } }];
51+
case '/api/v2/task-legacy':
52+
return { data: [] };
53+
case '/api/v2/project/1/dataset/1':
54+
return { id: 1, name: 'test' };
55+
case '/api/v2/project/1/status?dataset_id=1&workflow_id=1':
56+
return { status: {} }; // status is an empty object, since no tasks started
57+
case '/api/v2/project/1/workflow/1/job':
58+
return [
59+
{
60+
id: 1,
61+
project_id: 1,
62+
workflow_id: 1,
63+
dataset_id: 1,
64+
status: 'failed',
65+
log: 'Exception error occurred while creating job folder and subfolders.\nOriginal error: test'
66+
}
67+
];
68+
default:
69+
throw Error(`Unexpected API call: ${url}`);
70+
}
71+
}
72+
});
73+
});
74+
75+
const result = render(page);
76+
expect(
77+
await result.findByText(/Exception error occurred while creating job folder and subfolders/)
78+
).toBeDefined();
79+
});
80+
});

package-lock.json

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/v2/projects/[projectId]/workflows/[workflowId]/+page.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,13 @@
628628
}
629629
630630
async function loadJobError() {
631-
const failedStatus = Object.values(statuses).find((s) => s === 'failed');
632-
if (!failedStatus) {
633-
jobError = '';
634-
failedJob = undefined;
635-
return;
631+
if (Object.values(statuses).length > 0) {
632+
const failedStatus = Object.values(statuses).find((s) => s === 'failed');
633+
if (!failedStatus) {
634+
jobError = '';
635+
failedJob = undefined;
636+
return;
637+
}
636638
}
637639
const response = await fetch(`/api/v2/project/${project.id}/workflow/${workflow.id}/job`, {
638640
method: 'GET',
@@ -647,6 +649,8 @@
647649
.filter((j) => j.dataset_id === selectedDatasetId && j.status === 'failed')
648650
.sort((j1, j2) => (j1.start_timestamp < j2.start_timestamp ? 1 : -1));
649651
if (failedJobs.length === 0) {
652+
jobError = '';
653+
failedJob = undefined;
650654
return;
651655
}
652656
failedJob = failedJobs[0];

0 commit comments

Comments
 (0)