From f69406160f534b972f7c10c053e916fcd80a133d Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Tue, 29 Oct 2024 14:02:35 -0700 Subject: [PATCH] fix cancelation tests --- python_files/tests/pytestadapter/helpers.py | 3 ++- .../testController/pytest/pytestExecutionAdapter.ts | 1 + .../testController/unittest/testExecutionAdapter.ts | 1 + .../testCancellationRunAdapters.unit.test.ts | 12 ++++++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/python_files/tests/pytestadapter/helpers.py b/python_files/tests/pytestadapter/helpers.py index f2e392b49e6a..7a75e6248844 100644 --- a/python_files/tests/pytestadapter/helpers.py +++ b/python_files/tests/pytestadapter/helpers.py @@ -130,7 +130,8 @@ def parse_rpc_message(data: str) -> Tuple[Dict[str, str], str]: def _listen_on_fifo(pipe_name: str, result: List[str], completed: threading.Event): # Open the FIFO for reading - with open(pipe_name) as fifo: + fifo_path = pathlib.Path(pipe_name) + with fifo_path.open() as fifo: print("Waiting for data...") while True: if completed.is_set(): diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index a7578045b84a..716999770b0d 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -188,6 +188,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { resultProc?.kill(); } else { deferredTillExecClose.resolve(); + serverCancel.cancel(); } }); diff --git a/src/client/testing/testController/unittest/testExecutionAdapter.ts b/src/client/testing/testController/unittest/testExecutionAdapter.ts index e72d877e7617..f69ec4379908 100644 --- a/src/client/testing/testController/unittest/testExecutionAdapter.ts +++ b/src/client/testing/testController/unittest/testExecutionAdapter.ts @@ -190,6 +190,7 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { resultProc?.kill(); } else { deferredTillExecClose?.resolve(); + serverCancel.cancel(); } }); diff --git a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts index 0c8d09021cc5..1b90244fb41d 100644 --- a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts +++ b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts @@ -74,7 +74,6 @@ suite('Execution Flow Run Adapters', () => { .setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny())) .returns(() => { cancellationToken.cancel(); - deferredTillServerCloseTester?.resolve(); return { proc: mockProc as any, out: typeMoq.Mock.ofType>>().object, @@ -96,8 +95,12 @@ suite('Execution Flow Run Adapters', () => { return Promise.resolve('named-pipe'); }); - utilsStartRunResultNamedPipe.callsFake((_callback, deferredTillServerClose, _token) => { + utilsStartRunResultNamedPipe.callsFake((_callback, deferredTillServerClose, token) => { deferredTillServerCloseTester = deferredTillServerClose; + token?.onCancellationRequested(() => { + deferredTillServerCloseTester?.resolve(); + }); + return Promise.resolve('named-pipes-socket-name'); }); serverDisposeStub.callsFake(() => { @@ -140,7 +143,6 @@ suite('Execution Flow Run Adapters', () => { .setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny())) .returns(() => { cancellationToken.cancel(); - deferredTillServerCloseTester?.resolve(); return { proc: mockProc as any, out: typeMoq.Mock.ofType>>().object, @@ -164,6 +166,9 @@ suite('Execution Flow Run Adapters', () => { utilsStartRunResultNamedPipe.callsFake((_callback, deferredTillServerClose, _token) => { deferredTillServerCloseTester = deferredTillServerClose; + token?.onCancellationRequested(() => { + deferredTillServerCloseTester?.resolve(); + }); return Promise.resolve('named-pipes-socket-name'); }); serverDisposeStub.callsFake(() => { @@ -188,7 +193,6 @@ suite('Execution Flow Run Adapters', () => { }) .returns(async () => { cancellationToken.cancel(); - deferredTillServerCloseTester?.resolve(); return Promise.resolve(); });