Skip to content

Commit 93150f5

Browse files
committed
fix tests
1 parent 4d1162f commit 93150f5

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,13 @@ suite('pytest test execution adapter', () => {
390390

391391
await deferred2.promise;
392392
await deferred3.promise;
393+
await utilsStartRunResultNamedPipeStub.returnValues[0];
394+
395+
// Wait for runInBackground to be called
396+
await new Promise((resolve) => setImmediate(resolve));
393397

394398
// Trigger process exit
399+
sinon.assert.calledOnce(mockEnvProcess.onExit);
395400
const exitCallback = mockEnvProcess.onExit.firstCall.args[0];
396401
exitCallback(0, null);
397402

@@ -459,12 +464,19 @@ suite('pytest test execution adapter', () => {
459464

460465
await deferred2.promise;
461466
await deferred3.promise;
467+
await utilsStartRunResultNamedPipeStub.returnValues[0];
468+
469+
// Wait for runInBackground to be called
470+
await new Promise((resolve) => setImmediate(resolve));
462471

463472
// Trigger cancellation
464473
if (cancellationHandler) {
465474
cancellationHandler();
466475
}
467476

477+
// Wait for kill to be called
478+
await new Promise((resolve) => setImmediate(resolve));
479+
468480
// Verify process.kill was called
469481
sinon.assert.calledOnce(mockEnvProcess.kill);
470482

@@ -499,10 +511,19 @@ suite('pytest test execution adapter', () => {
499511
const uri = Uri.file(myTestPath);
500512
adapter = new PytestTestExecutionAdapter(configService);
501513

502-
await adapter.runTests(uri, ['test1'], TestRunProfileKind.Run, testRun.object, execFactory.object);
514+
const runPromise = adapter.runTests(
515+
uri,
516+
['test1'],
517+
TestRunProfileKind.Run,
518+
testRun.object,
519+
execFactory.object,
520+
);
503521

504522
await deferred2.promise;
505523
await deferred3.promise;
524+
await utilsStartRunResultNamedPipeStub.returnValues[0];
525+
526+
await runPromise;
506527

507528
// Verify runInBackground was NOT called
508529
sinon.assert.notCalled(runInBackgroundStub);
@@ -548,6 +569,10 @@ suite('pytest test execution adapter', () => {
548569

549570
await deferred2.promise;
550571
await deferred3.promise;
572+
await utilsStartRunResultNamedPipeStub.returnValues[0];
573+
574+
// Wait for runInBackground to be called
575+
await new Promise((resolve) => setImmediate(resolve));
551576

552577
// Trigger process exit
553578
const exitCallback = mockEnvProcess.onExit.firstCall.args[0];
@@ -605,6 +630,10 @@ suite('pytest test execution adapter', () => {
605630

606631
await deferred2.promise;
607632
await deferred3.promise;
633+
await utilsStartRunResultNamedPipeStub.returnValues[0];
634+
635+
// Wait for runInBackground to be called
636+
await new Promise((resolve) => setImmediate(resolve));
608637

609638
// Trigger process exit with error code
610639
const exitCallback = mockEnvProcess.onExit.firstCall.args[0];
@@ -665,12 +694,16 @@ suite('pytest test execution adapter', () => {
665694
await deferred2.promise;
666695
await deferred3.promise;
667696
await deferred4.promise;
697+
await utilsStartRunResultNamedPipeStub.returnValues[0];
668698

669699
// Trigger cancellation
670700
if (cancellationHandler) {
671701
cancellationHandler();
672702
}
673703

704+
// Wait for kill to be processed
705+
await new Promise((resolve) => setImmediate(resolve));
706+
674707
// Verify process.kill was called
675708
sinon.assert.calledOnce(killStub);
676709

@@ -714,10 +747,12 @@ suite('pytest test execution adapter', () => {
714747
await deferred2.promise;
715748
await deferred3.promise;
716749
await deferred4.promise;
750+
await utilsStartRunResultNamedPipeStub.returnValues[0];
717751

718752
// Access private activeInstances to verify cleanup
719753
const activeInstances = (adapter as any).activeInstances;
720754
const instanceCountBefore = activeInstances.size;
755+
assert.strictEqual(instanceCountBefore, 1, 'Should have one active instance');
721756

722757
// Trigger process close
723758
mockProc.trigger('close');
@@ -726,7 +761,7 @@ suite('pytest test execution adapter', () => {
726761

727762
// Verify instance was cleaned up
728763
const instanceCountAfter = activeInstances.size;
729-
assert.strictEqual(instanceCountAfter, instanceCountBefore, 'Instance should be removed after close');
764+
assert.strictEqual(instanceCountAfter, 0, 'Instance should be removed after close');
730765
});
731766

732767
test('Promise resolution happens correctly on success', async () => {
@@ -765,6 +800,7 @@ suite('pytest test execution adapter', () => {
765800
await deferred2.promise;
766801
await deferred3.promise;
767802
await deferred4.promise;
803+
await utilsStartRunResultNamedPipeStub.returnValues[0];
768804

769805
// Trigger successful close (exit code 0, no signal)
770806
mockProc.trigger('close');
@@ -811,6 +847,7 @@ suite('pytest test execution adapter', () => {
811847
await deferred2.promise;
812848
await deferred3.promise;
813849
await deferred4.promise;
850+
await utilsStartRunResultNamedPipeStub.returnValues[0];
814851

815852
// Trigger error close (exit code 1, SIGTERM signal)
816853
mockProc.trigger('close');

src/test/testing/testController/testCancellationRunAdapters.unit.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ suite('Execution Flow Run Adapters', () => {
8080
// run result pipe mocking and the related server close dispose
8181
let deferredTillServerCloseTester: Deferred<void> | undefined;
8282

83+
// Create a real MockChildProcess so we can trigger events
84+
const realMockProc = new MockChildProcess('', ['']);
85+
8386
// // mock exec service and exec factory
8487
execServiceStub
8588
.setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny()))
8689
.returns(() => {
87-
cancellationToken.cancel();
90+
// Schedule cancellation to happen asynchronously
91+
setImmediate(() => cancellationToken.cancel());
8892
return {
89-
proc: mockProc as any,
93+
proc: realMockProc as any,
9094
out: typeMoq.Mock.ofType<Observable<Output<string>>>().object,
9195
dispose: () => {
9296
/* no-body */
@@ -128,16 +132,25 @@ suite('Execution Flow Run Adapters', () => {
128132

129133
// define adapter and run tests
130134
const testAdapter = createAdapter(adapter, configService);
131-
await testAdapter.runTests(
135+
const runPromise = testAdapter.runTests(
132136
Uri.file(myTestPath),
133137
[],
134138
TestRunProfileKind.Run,
135139
testRunMock.object,
136140
execFactoryStub.object,
137141
debugLauncher.object,
138142
);
143+
139144
// wait for server to start to keep test from failing
140145
await deferredStartTestIdsNamedPipe.promise;
146+
147+
// Wait for cancellation to be processed
148+
await new Promise((resolve) => setTimeout(resolve, 50));
149+
150+
// Trigger process close event to allow promise to resolve
151+
realMockProc.trigger('close');
152+
153+
await runPromise;
141154
});
142155
test(`Adapter ${adapter}: token called mid-debug resolves correctly`, async () => {
143156
// mock test run and cancelation token

0 commit comments

Comments
 (0)