Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from fastapi import (FastAPI, APIRouter, Response, Request, status, UploadFile)
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
import asyncio
from datetime import datetime
import json
from json import JSONDecodeError
Expand Down Expand Up @@ -350,9 +351,17 @@ async def stop_testrun(self, response: Response):
response.status_code = 404
return self._generate_msg(False, "Testrun is not currently running")

self._testrun.stop()
# Launch stop in the background
asyncio.create_task(self._run_stop())

return self._generate_msg(True, "Testrun stopped")
# Return response immediately
return self._generate_msg(True, "Testrun stop initiated")

async def _run_stop(self):
try:
await self._testrun.stop() # Assuming .stop is async
except Exception as e:
LOGGER.exception("Error while stopping testrun: %s", e)

async def get_status(self):
return self._testrun.get_session().to_json()
Expand Down
2 changes: 1 addition & 1 deletion framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def start(self):
while True:
time.sleep(5)

def stop(self):
async def stop(self):

# First, change the status to stopping
self.get_session().stop()
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/model/testrun-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export enum StatusOfTestrun {
WaitingForDevice = 'Waiting for Device',
Cancelled = 'Cancelled',
Cancelling = 'Cancelling',
Stopping = 'Stopping',
Failed = 'Failed',
CompliantLimited = 'Compliant (Limited)',
CompliantHigh = 'Compliant (High)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
*ngSwitchCase="StatusOfTestrun.Cancelling"
[ngTemplateOutlet]="Cancelling">
</ng-container>
<ng-container
*ngSwitchCase="StatusOfTestrun.Stopping"
[ngTemplateOutlet]="Cancelling">
</ng-container>
</div>

<ng-container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('ProgressStatusCardComponent', () => {
StatusOfTestrun.WaitingForDevice,
StatusOfTestrun.Monitoring,
StatusOfTestrun.Cancelling,
StatusOfTestrun.Stopping,
];

const statusesForCompletedSuccessClass = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export class TestrunStatusCardComponent {
} {
return {
progress:
this.isProgressStatus(status) || status === StatusOfTestrun.Cancelling,
this.isProgressStatus(status) ||
status === StatusOfTestrun.Cancelling ||
status === StatusOfTestrun.Stopping,
'completed-success':
(result === ResultOfTestrun.Compliant &&
status === StatusOfTestrun.Complete) ||
Expand All @@ -92,6 +94,7 @@ export class TestrunStatusCardComponent {
data.status === StatusOfTestrun.InProgress ||
data.status === StatusOfTestrun.Cancelled ||
data.status === StatusOfTestrun.Cancelling ||
data.status === StatusOfTestrun.Stopping ||
data.finished
) {
if (
Expand Down Expand Up @@ -126,6 +129,9 @@ export class TestrunStatusCardComponent {
) {
return data.result!;
}
if (data.status === StatusOfTestrun.Stopping) {
return StatusOfTestrun.Cancelling;
}
return data.status;
}

Expand Down
4 changes: 3 additions & 1 deletion modules/ui/src/app/pages/testrun/testrun.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
isTestrunInProgress(data.status) ||
data.status === StatusOfTestrun.Cancelled ||
data.status === StatusOfTestrun.Cancelling ||
data.status === StatusOfTestrun.Stopping ||
data.finished
">
<mat-toolbar class="progress-toolbar">
Expand Down Expand Up @@ -115,7 +116,8 @@
hasDevices === false ||
isAllDevicesOutdated === true ||
isTestrunInProgress(systemStatus?.status) ||
systemStatus?.status === StatusOfTestrun.Cancelling
systemStatus?.status === StatusOfTestrun.Cancelling ||
systemStatus?.status === StatusOfTestrun.Stopping
"
(click)="openTestRunModal(vm.testModules)"
mat-flat-button>
Expand Down
2 changes: 0 additions & 2 deletions modules/ui/src/app/store/effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
MOCK_PROGRESS_DATA_WAITING_FOR_DEVICE,
} from '../mocks/testrun.mock';
import {
fetchSystemStatus,
fetchSystemStatusSuccess,
setReports,
setStatus,
Expand Down Expand Up @@ -339,7 +338,6 @@ describe('Effects', () => {

effects.onStopTestrun$.subscribe(() => {
expect(testRunServiceMock.stopTestrun).toHaveBeenCalled();
expect(dispatchSpy).toHaveBeenCalledWith(fetchSystemStatus());
done();
});
});
Expand Down
18 changes: 7 additions & 11 deletions modules/ui/src/app/store/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
TestrunStatus,
} from '../model/testrun-status';
import {
fetchSystemStatus,
fetchSystemStatusSuccess,
setIsTestingComplete,
setReports,
Expand Down Expand Up @@ -137,7 +136,8 @@ export class AppEffects {
map(({ systemStatus }) => {
const isInProgressDevice =
this.testrunService.testrunInProgress(systemStatus?.status) ||
systemStatus.status === StatusOfTestrun.Cancelling;
systemStatus.status === StatusOfTestrun.Cancelling ||
systemStatus.status === StatusOfTestrun.Stopping;
return AppActions.setDeviceInProgress({
device: isInProgressDevice ? systemStatus.device : null,
});
Expand All @@ -163,14 +163,7 @@ export class AppEffects {
return this.actions$.pipe(
ofType(AppActions.setIsStopTestrun),
switchMap(() => {
this.store.dispatch(stopInterval());
return this.testrunService.stopTestrun().pipe(
map(stopped => {
if (stopped) {
this.store.dispatch(fetchSystemStatus());
}
})
);
return this.testrunService.stopTestrun();
})
);
},
Expand Down Expand Up @@ -200,7 +193,10 @@ export class AppEffects {
isTestingComplete: this.isTestrunFinished(systemStatus.status),
})
);
if (this.testrunService.testrunInProgress(systemStatus.status)) {
if (
this.testrunService.testrunInProgress(systemStatus.status) ||
systemStatus.status === StatusOfTestrun.Stopping
) {
this.pullingSystemStatusData();
this.fetchInternetConnection();
} else if (
Expand Down