From dc09679ae253cb9f3c150dbce80cb7f28ec74eff Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 8 May 2025 15:39:30 +0100 Subject: [PATCH 1/2] Async stop method for Firefox bug --- framework/python/src/api/api.py | 13 +++++++++++-- framework/python/src/core/testrun.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index 78b3925fa..f1a32c1e6 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -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 @@ -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() diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 4bc8b20c5..b2a731395 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -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() From 632d67f3a0bee691dd93e3cd0116c3f46a8ebba1 Mon Sep 17 00:00:00 2001 From: Olga Mardvilko Date: Wed, 14 May 2025 12:23:31 +0200 Subject: [PATCH 2/2] 413636459: (fix) changes to continue pulling status on cancelling the test (#1293) * 413636459: (fix) changes to continue pulling status on cancelling the test * 413636459: (fix) remove fetching status after stop test attemp * 413636459: (fix) use stopping status to continue polling statuses * 413636459: (fix) changes for stopping status to display as cancelling in ui --- modules/ui/src/app/model/testrun-status.ts | 1 + .../testrun-status-card.component.html | 4 ++++ .../testrun-status-card.component.spec.ts | 1 + .../testrun-status-card.component.ts | 8 +++++++- .../app/pages/testrun/testrun.component.html | 4 +++- modules/ui/src/app/store/effects.spec.ts | 2 -- modules/ui/src/app/store/effects.ts | 18 +++++++----------- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/modules/ui/src/app/model/testrun-status.ts b/modules/ui/src/app/model/testrun-status.ts index a990a2a45..77473aa2b 100644 --- a/modules/ui/src/app/model/testrun-status.ts +++ b/modules/ui/src/app/model/testrun-status.ts @@ -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)', diff --git a/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.html b/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.html index a459e1744..2ba1a0664 100644 --- a/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.html +++ b/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.html @@ -66,6 +66,10 @@ *ngSwitchCase="StatusOfTestrun.Cancelling" [ngTemplateOutlet]="Cancelling"> + + { StatusOfTestrun.WaitingForDevice, StatusOfTestrun.Monitoring, StatusOfTestrun.Cancelling, + StatusOfTestrun.Stopping, ]; const statusesForCompletedSuccessClass = [ diff --git a/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.ts b/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.ts index 6c8055c86..a3458244e 100644 --- a/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.ts +++ b/modules/ui/src/app/pages/testrun/components/testrun-status-card/testrun-status-card.component.ts @@ -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) || @@ -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 ( @@ -126,6 +129,9 @@ export class TestrunStatusCardComponent { ) { return data.result!; } + if (data.status === StatusOfTestrun.Stopping) { + return StatusOfTestrun.Cancelling; + } return data.status; } diff --git a/modules/ui/src/app/pages/testrun/testrun.component.html b/modules/ui/src/app/pages/testrun/testrun.component.html index f55fee725..f9b95f948 100644 --- a/modules/ui/src/app/pages/testrun/testrun.component.html +++ b/modules/ui/src/app/pages/testrun/testrun.component.html @@ -20,6 +20,7 @@ isTestrunInProgress(data.status) || data.status === StatusOfTestrun.Cancelled || data.status === StatusOfTestrun.Cancelling || + data.status === StatusOfTestrun.Stopping || data.finished "> @@ -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> diff --git a/modules/ui/src/app/store/effects.spec.ts b/modules/ui/src/app/store/effects.spec.ts index 7ca894c27..952b9dbf6 100644 --- a/modules/ui/src/app/store/effects.spec.ts +++ b/modules/ui/src/app/store/effects.spec.ts @@ -37,7 +37,6 @@ import { MOCK_PROGRESS_DATA_WAITING_FOR_DEVICE, } from '../mocks/testrun.mock'; import { - fetchSystemStatus, fetchSystemStatusSuccess, setReports, setStatus, @@ -339,7 +338,6 @@ describe('Effects', () => { effects.onStopTestrun$.subscribe(() => { expect(testRunServiceMock.stopTestrun).toHaveBeenCalled(); - expect(dispatchSpy).toHaveBeenCalledWith(fetchSystemStatus()); done(); }); }); diff --git a/modules/ui/src/app/store/effects.ts b/modules/ui/src/app/store/effects.ts index 69c86f2bd..278cc1bb0 100644 --- a/modules/ui/src/app/store/effects.ts +++ b/modules/ui/src/app/store/effects.ts @@ -38,7 +38,6 @@ import { TestrunStatus, } from '../model/testrun-status'; import { - fetchSystemStatus, fetchSystemStatusSuccess, setIsTestingComplete, setReports, @@ -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, }); @@ -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(); }) ); }, @@ -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 (