Skip to content

Commit

Permalink
#145 fixed script executor selection after HTTP error
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Sep 18, 2020
1 parent 7e029c7 commit 4cbf43d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 4 additions & 2 deletions web-src/src/main-app/store/scriptExecutionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ export default {

selectExecutor({commit, state, dispatch}, executor) {
const currentExecutor = state.currentExecutor;
if ((!isNull(currentExecutor))) {
if (executor && (executor.state.id === currentExecutor.state.id)) {
if (!isNull(currentExecutor)) {
// Don't remove finished executor automatically, if it was cleaned up
// unless id is null, meaning it was an error
if (executor && !isNull(executor.state.id) && (executor.state.id === currentExecutor.state.id)) {
return;
}

Expand Down
25 changes: 23 additions & 2 deletions web-src/tests/unit/main-app/store/scriptExecutionManager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function mockActiveExecutions(executions) {
}
}

function mockStartResponse(id) {
axiosMock.onPost('executions/start').reply(200, id);
function mockStartResponse(id, status = 200) {
axiosMock.onPost('executions/start').reply(status, id);
}

describe('Test scriptExecutionManager', function () {
Expand Down Expand Up @@ -148,6 +148,27 @@ describe('Test scriptExecutionManager', function () {

assertSelectedExecutor(12);
});

it('Test startExecution twice, when first is error', async function () {
store.state.scripts.selectedScript = 'abc';

mockStartResponse(null, 500);

await store.dispatch('executions/startExecution');
await flushPromises();

const currentExecutor = store.state.executions.currentExecutor;
expect(currentExecutor).not.toBeNil();
expect(currentExecutor.state.id).toBeNil();
expect(currentExecutor.state.scriptName).toEqual('abc');

mockStartResponse(123);

await store.dispatch('executions/startExecution');
await flushPromises();

assertSelectedExecutor(123);
});
});

describe('Test selectExecutor', function () {
Expand Down

0 comments on commit 4cbf43d

Please sign in to comment.