Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] Automate Workspace stopping by idle timeout test-case #22552

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions tests/e2e/specs/miscellaneous/WorkspaceIdleTimeout.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** *******************************************************************
* copyright (c) 2020-2023 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { LoginTests } from '../../tests-library/LoginTests';
import { registerRunningWorkspace } from '../MochaHooks';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
import { Workspaces } from '../../pageobjects/dashboard/Workspaces';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
import { DriverHelper } from '../../utils/DriverHelper';
import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader';
import { Locators, ModalDialog } from 'monaco-page-objects';
import { expect } from 'chai';
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../../utils/ShellExecutor';

suite('"Check workspace idle timeout" test', function (): void {
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
const workspaces: Workspaces = e2eContainer.get(CLASSES.Workspaces);
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader);
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor);

const stackName: string = 'Empty Workspace';
const cheClusterName: string = 'devspaces';
let stopWorkspaceTimeout: number = 0;

suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp('admin');
shellExecutor.executeCommand('oc project openshift-devspaces');

// get current value of spec.devEnvironments.secondsOfInactivityBeforeIdling
stopWorkspaceTimeout = Number(
shellExecutor.executeCommand(
`oc get checluster/${cheClusterName} -o "jsonpath={.spec.devEnvironments.secondsOfInactivityBeforeIdling}"`
)
);

// set spec.devEnvironments.secondsOfInactivityBeforeIdling to 60
shellExecutor.executeCommand(
`oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": 60}}}'`
);
});

suiteTeardown(function (): void {
// restore spec.devEnvironments.secondsOfInactivityBeforeIdling to original value
shellExecutor.executeCommand(
`oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": ${stopWorkspaceTimeout}}}}'`
);
});

loginTests.loginIntoChe();

test(`Create and open new workspace, stack:${stackName}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspace(stackName);
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
});

test('Wait workspace readiness', async function (): Promise<void> {
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
await projectAndFileTests.performTrustAuthorDialog();
});

test('Wait idle timeout dialog and click on "Return to Dashboard" button', async function (): Promise<void> {
dmytro-ndp marked this conversation as resolved.
Show resolved Hide resolved
await driverHelper.waitVisibility(webCheCodeLocators.Dialog.details, TIMEOUT_CONSTANTS.TS_SELENIUM_START_WORKSPACE_TIMEOUT);
const dialog: ModalDialog = new ModalDialog();
expect(await dialog.getDetails()).includes('Your workspace has stopped due to inactivity.');
await dialog.pushButton('Return to dashboard');
});

test('Check that the workskpace has Stopped state', async function (): Promise<void> {
await dashboard.waitPage();
await workspaces.waitWorkspaceWithStoppedStatus(WorkspaceHandlingTests.getWorkspaceName());
});

test('Delete the workspace', async function (): Promise<void> {
await dashboard.deleteStoppedWorkspaceByUI(WorkspaceHandlingTests.getWorkspaceName());
});

loginTests.logoutFromChe();
});
Loading