Skip to content

Commit

Permalink
fix: remove conditions before restart a workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Sep 10, 2024
1 parent 49a7631 commit 0304388
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,68 @@ describe('DevWorkspace store, actions', () => {
expect(actions).toStrictEqual(expectedActions);
});

it('should remove all workspace conditions in the store before start a DevWorkspace', async () => {
(checkRunningWorkspacesLimit as jest.Mock).mockImplementation(() => undefined);
(isRunningDevWorkspacesClusterLimitExceeded as jest.Mock).mockReturnValue(
Promise.resolve(true),
);

// set a condition with an error message to the devWorkspace
devWorkspace.status = {
devworkspaceId: '1234',
conditions: [
{
type: 'Stopped',
status: 'False',
reason: 'LimitReached',
message: 'Workspace stopped due to error.',
},
],
};

const store = storeBuilder.withDevWorkspaces({ workspaces: [devWorkspace] }).build();

await store.dispatch(testStore.actionCreators.startWorkspace(devWorkspace));

const actions = store.getActions();

const expectedActions: Array<
| testStore.KnownAction
| testDevWorkspaceClusterStore.KnownAction
| ServerConfigStore.KnownAction
> = [
{
type: testStore.Type.UPDATE_DEVWORKSPACE,
workspace: devWorkspace,
},
{
type: testDevWorkspaceClusterStore.Type.REQUEST_DEVWORKSPACES_CLUSTER,
check: AUTHORIZED,
},
{
type: testDevWorkspaceClusterStore.Type.RECEIVED_DEVWORKSPACES_CLUSTER,
isRunningDevWorkspacesClusterLimitExceeded: true,
},
{
type: testStore.Type.REQUEST_DEVWORKSPACE,
check: AUTHORIZED,
},
{
type: 'REQUEST_DW_SERVER_CONFIG',
},
{
config: {} as api.IServerConfig,
type: 'RECEIVE_DW_SERVER_CONFIG',
},
{
type: testStore.Type.UPDATE_DEVWORKSPACE,
workspace: devWorkspace,
},
];

expect(actions).toStrictEqual(expectedActions);
});

it('should create REQUEST_DEVWORKSPACE and RECEIVE_DEVWORKSPACE_ERROR when failed to start a DevWorkspace', async () => {
(checkRunningWorkspacesLimit as jest.Mock).mockImplementation(() => {
throw new Error('Limit reached.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ export const actionCreators: ActionCreators = {
console.warn(`Workspace ${_workspace.metadata.name} already started`);
return;
}
if (workspace.status?.conditions && workspace.status?.conditions?.length > 0) {
workspace.status.conditions = [];
dispatch({
type: Type.UPDATE_DEVWORKSPACE,
workspace,
});
}
try {
await OAuthService.refreshTokenIfProjectExists(workspace);
await dispatch(
Expand Down

0 comments on commit 0304388

Please sign in to comment.