Skip to content

Commit 2ad6cde

Browse files
committed
test fixes
1 parent dd9288f commit 2ad6cde

File tree

1 file changed

+63
-69
lines changed

1 file changed

+63
-69
lines changed

src/test/testing/common/testingAdapter.test.ts

Lines changed: 63 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,10 @@ suite('End to End Tests: test adapters', () => {
161161
resultResolver = new PythonResultResolver(testController, unittestProvider, workspaceUri);
162162
let callCount = 0;
163163
// const deferredTillEOT = createTestingDeferred();
164-
resultResolver.resolveDiscovery = async (payload, _token?) => {
164+
resultResolver.resolveDiscovery = (payload, _token?) => {
165165
traceLog(`resolveDiscovery ${payload}`);
166166
callCount = callCount + 1;
167167
actualData = payload;
168-
return Promise.resolve();
169168
};
170169

171170
// set workspace to test workspace folder and set up settings
@@ -202,11 +201,10 @@ suite('End to End Tests: test adapters', () => {
202201
};
203202
resultResolver = new PythonResultResolver(testController, unittestProvider, workspaceUri);
204203
let callCount = 0;
205-
resultResolver.resolveDiscovery = async (payload, _token?) => {
204+
resultResolver.resolveDiscovery = (payload, _token?) => {
206205
traceLog(`resolveDiscovery ${payload}`);
207206
callCount = callCount + 1;
208207
actualData = payload;
209-
return Promise.resolve();
210208
};
211209

212210
// set settings to work for the given workspace
@@ -242,10 +240,9 @@ suite('End to End Tests: test adapters', () => {
242240
workspaceUri = Uri.parse(rootPathSmallWorkspace);
243241
resultResolver = new PythonResultResolver(testController, pytestProvider, workspaceUri);
244242
let callCount = 0;
245-
resultResolver.resolveDiscovery = async (payload, _token?) => {
243+
resultResolver.resolveDiscovery = (payload, _token?) => {
246244
callCount = callCount + 1;
247245
actualData = payload;
248-
return Promise.resolve();
249246
};
250247
// run pytest discovery
251248
const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService);
@@ -291,11 +288,10 @@ suite('End to End Tests: test adapters', () => {
291288

292289
resultResolver = new PythonResultResolver(testController, pytestProvider, workspaceUri);
293290
let callCount = 0;
294-
resultResolver.resolveDiscovery = async (payload, _token?) => {
291+
resultResolver.resolveDiscovery = (payload, _token?) => {
295292
traceLog(`resolveDiscovery ${payload}`);
296293
callCount = callCount + 1;
297294
actualData = payload;
298-
return Promise.resolve();
299295
};
300296
// run pytest discovery
301297
const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService);
@@ -375,11 +371,10 @@ suite('End to End Tests: test adapters', () => {
375371

376372
resultResolver = new PythonResultResolver(testController, pytestProvider, workspaceUri);
377373
let callCount = 0;
378-
resultResolver.resolveDiscovery = async (payload, _token?) => {
374+
resultResolver.resolveDiscovery = (payload, _token?) => {
379375
traceLog(`resolveDiscovery ${payload}`);
380376
callCount = callCount + 1;
381377
actualData = payload;
382-
return Promise.resolve();
383378
};
384379
// run pytest discovery
385380
const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService);
@@ -446,11 +441,10 @@ suite('End to End Tests: test adapters', () => {
446441
};
447442
resultResolver = new PythonResultResolver(testController, pytestProvider, workspaceUri);
448443
let callCount = 0;
449-
resultResolver.resolveDiscovery = async (payload, _token?) => {
444+
resultResolver.resolveDiscovery = (payload, _token?) => {
450445
traceLog(`resolveDiscovery ${payload}`);
451446
callCount = callCount + 1;
452447
actualData = payload;
453-
return Promise.resolve();
454448
};
455449
// run pytest discovery
456450
const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService);
@@ -480,22 +474,23 @@ suite('End to End Tests: test adapters', () => {
480474
let callCount = 0;
481475
let failureOccurred = false;
482476
let failureMsg = '';
483-
resultResolver.resolveExecution = async (payload, _token?) => {
477+
resultResolver.resolveExecution = (payload, _token?) => {
484478
traceLog(`resolveDiscovery ${payload}`);
485479
callCount = callCount + 1;
486480
// the payloads that get to the _resolveExecution are all data and should be successful.
487481
try {
488-
assert.strictEqual(
489-
payload.status,
490-
'success',
491-
`Expected status to be 'success', instead status is ${payload.status}`,
492-
);
493-
assert.ok(payload.result, 'Expected results to be present');
482+
if ('status' in payload) {
483+
assert.strictEqual(
484+
payload.status,
485+
'success',
486+
`Expected status to be 'success', instead status is ${payload.status}`,
487+
);
488+
assert.ok(payload.result, 'Expected results to be present');
489+
}
494490
} catch (err) {
495491
failureMsg = err ? (err as Error).toString() : '';
496492
failureOccurred = true;
497493
}
498-
return Promise.resolve();
499494
};
500495

501496
// set workspace to test workspace folder
@@ -554,22 +549,25 @@ suite('End to End Tests: test adapters', () => {
554549
let callCount = 0;
555550
let failureOccurred = false;
556551
let failureMsg = '';
557-
resultResolver.resolveExecution = async (payload, _token?) => {
552+
resultResolver.resolveExecution = (payload, _token?) => {
558553
traceLog(`resolveDiscovery ${payload}`);
559554
callCount = callCount + 1;
560555
// the payloads that get to the _resolveExecution are all data and should be successful.
561556
try {
562-
const validStatuses = ['subtest-success', 'subtest-failure'];
563-
assert.ok(
564-
validStatuses.includes(payload.status),
565-
`Expected status to be one of ${validStatuses.join(', ')}, but instead status is ${payload.status}`,
566-
);
567-
assert.ok(payload.result, 'Expected results to be present');
557+
if ('status' in payload) {
558+
const validStatuses = ['subtest-success', 'subtest-failure'];
559+
assert.ok(
560+
validStatuses.includes(payload.status),
561+
`Expected status to be one of ${validStatuses.join(', ')}, but instead status is ${
562+
payload.status
563+
}`,
564+
);
565+
assert.ok(payload.result, 'Expected results to be present');
566+
}
568567
} catch (err) {
569568
failureMsg = err ? (err as Error).toString() : '';
570569
failureOccurred = true;
571570
}
572-
return Promise.resolve();
573571
};
574572

575573
// set workspace to test workspace folder
@@ -625,22 +623,23 @@ suite('End to End Tests: test adapters', () => {
625623
let callCount = 0;
626624
let failureOccurred = false;
627625
let failureMsg = '';
628-
resultResolver.resolveExecution = async (payload, _token?) => {
626+
resultResolver.resolveExecution = (payload, _token?) => {
629627
traceLog(`resolveDiscovery ${payload}`);
630628
callCount = callCount + 1;
631629
// the payloads that get to the _resolveExecution are all data and should be successful.
632630
try {
633-
assert.strictEqual(
634-
payload.status,
635-
'success',
636-
`Expected status to be 'success', instead status is ${payload.status}`,
637-
);
638-
assert.ok(payload.result, 'Expected results to be present');
631+
if ('status' in payload) {
632+
assert.strictEqual(
633+
payload.status,
634+
'success',
635+
`Expected status to be 'success', instead status is ${payload.status}`,
636+
);
637+
assert.ok(payload.result, 'Expected results to be present');
638+
}
639639
} catch (err) {
640640
failureMsg = err ? (err as Error).toString() : '';
641641
failureOccurred = true;
642642
}
643-
return Promise.resolve();
644643
};
645644
// set workspace to test workspace folder
646645
workspaceUri = Uri.parse(rootPathSmallWorkspace);
@@ -707,7 +706,7 @@ suite('End to End Tests: test adapters', () => {
707706
test('Unittest execution with coverage, small workspace', async () => {
708707
// result resolver and saved data for assertions
709708
resultResolver = new PythonResultResolver(testController, unittestProvider, workspaceUri);
710-
resultResolver._resolveCoverage = async (payload, _token?) => {
709+
resultResolver._resolveCoverage = (payload, _token?) => {
711710
assert.strictEqual(payload.cwd, rootPathCoverageWorkspace, 'Expected cwd to be the workspace folder');
712711
assert.ok(payload.result, 'Expected results to be present');
713712
const simpleFileCov = payload.result[`${rootPathCoverageWorkspace}/even.py`];
@@ -717,7 +716,6 @@ suite('End to End Tests: test adapters', () => {
717716
assert.strictEqual(simpleFileCov.lines_missed.length, 1, 'Expected 3 lines to be missed in even.py');
718717
assert.strictEqual(simpleFileCov.executed_branches, 1, 'Expected 1 branch to be executed in even.py');
719718
assert.strictEqual(simpleFileCov.total_branches, 2, 'Expected 2 branches in even.py');
720-
return Promise.resolve();
721719
};
722720

723721
// set workspace to test workspace folder
@@ -757,7 +755,7 @@ suite('End to End Tests: test adapters', () => {
757755
test('pytest coverage execution, small workspace', async () => {
758756
// result resolver and saved data for assertions
759757
resultResolver = new PythonResultResolver(testController, pytestProvider, workspaceUri);
760-
resultResolver._resolveCoverage = async (payload, _runInstance?) => {
758+
resultResolver._resolveCoverage = (payload, _runInstance?) => {
761759
assert.strictEqual(payload.cwd, rootPathCoverageWorkspace, 'Expected cwd to be the workspace folder');
762760
assert.ok(payload.result, 'Expected results to be present');
763761
const simpleFileCov = payload.result[`${rootPathCoverageWorkspace}/even.py`];
@@ -767,8 +765,6 @@ suite('End to End Tests: test adapters', () => {
767765
assert.strictEqual(simpleFileCov.lines_missed.length, 1, 'Expected 3 lines to be missed in even.py');
768766
assert.strictEqual(simpleFileCov.executed_branches, 1, 'Expected 1 branch to be executed in even.py');
769767
assert.strictEqual(simpleFileCov.total_branches, 2, 'Expected 2 branches in even.py');
770-
771-
return Promise.resolve();
772768
};
773769
// set workspace to test workspace folder
774770
workspaceUri = Uri.parse(rootPathCoverageWorkspace);
@@ -811,22 +807,23 @@ suite('End to End Tests: test adapters', () => {
811807
let callCount = 0;
812808
let failureOccurred = false;
813809
let failureMsg = '';
814-
resultResolver.resolveExecution = async (payload, _token?) => {
810+
resultResolver.resolveExecution = (payload, _token?) => {
815811
traceLog(`resolveDiscovery ${payload}`);
816812
callCount = callCount + 1;
817813
// the payloads that get to the _resolveExecution are all data and should be successful.
818814
try {
819-
assert.strictEqual(
820-
payload.status,
821-
'success',
822-
`Expected status to be 'success', instead status is ${payload.status}`,
823-
);
824-
assert.ok(payload.result, 'Expected results to be present');
815+
if ('status' in payload) {
816+
assert.strictEqual(
817+
payload.status,
818+
'success',
819+
`Expected status to be 'success', instead status is ${payload.status}`,
820+
);
821+
assert.ok(payload.result, 'Expected results to be present');
822+
}
825823
} catch (err) {
826824
failureMsg = err ? (err as Error).toString() : '';
827825
failureOccurred = true;
828826
}
829-
return Promise.resolve();
830827
};
831828

832829
// set workspace to test workspace folder
@@ -878,7 +875,7 @@ suite('End to End Tests: test adapters', () => {
878875
let callCount = 0;
879876
let failureOccurred = false;
880877
let failureMsg = '';
881-
resultResolver.resolveDiscovery = async (data, _token?) => {
878+
resultResolver.resolveDiscovery = (data, _token?) => {
882879
// do the following asserts for each time resolveExecution is called, should be called once per test.
883880
callCount = callCount + 1;
884881
traceLog(`unittest discovery adapter seg fault error handling \n ${JSON.stringify(data)}`);
@@ -903,7 +900,6 @@ suite('End to End Tests: test adapters', () => {
903900
failureMsg = err ? (err as Error).toString() : '';
904901
failureOccurred = true;
905902
}
906-
return Promise.resolve();
907903
};
908904

909905
// set workspace to test workspace folder
@@ -931,7 +927,7 @@ suite('End to End Tests: test adapters', () => {
931927
let callCount = 0;
932928
let failureOccurred = false;
933929
let failureMsg = '';
934-
resultResolver.resolveDiscovery = async (data, _token?) => {
930+
resultResolver.resolveDiscovery = (data, _token?) => {
935931
// do the following asserts for each time resolveExecution is called, should be called once per test.
936932
callCount = callCount + 1;
937933
traceLog(`add one to call count, is now ${callCount}`);
@@ -961,7 +957,6 @@ suite('End to End Tests: test adapters', () => {
961957
failureMsg = err ? (err as Error).toString() : '';
962958
failureOccurred = true;
963959
}
964-
return Promise.resolve();
965960
};
966961
// run pytest discovery
967962
const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService);
@@ -984,22 +979,24 @@ suite('End to End Tests: test adapters', () => {
984979
let callCount = 0;
985980
let failureOccurred = false;
986981
let failureMsg = '';
987-
resultResolver.resolveExecution = async (data, _token?) => {
982+
resultResolver.resolveExecution = (data, _token?) => {
988983
// do the following asserts for each time resolveExecution is called, should be called once per test.
989984
console.log(`pytest execution adapter seg fault error handling \n ${JSON.stringify(data)}`);
990985
callCount = callCount + 1;
991986
try {
992-
if (data.status === 'error') {
993-
assert.ok(data.error, "Expected errors in 'error' field");
994-
} else {
995-
const indexOfTest = JSON.stringify(data.result).search('error');
996-
assert.notDeepEqual(
997-
indexOfTest,
998-
-1,
999-
'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.',
1000-
);
987+
if ('status' in data) {
988+
if (data.status === 'error') {
989+
assert.ok(data.error, "Expected errors in 'error' field");
990+
} else {
991+
const indexOfTest = JSON.stringify(data.result).search('error');
992+
assert.notDeepEqual(
993+
indexOfTest,
994+
-1,
995+
'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.',
996+
);
997+
}
998+
assert.ok(data.result, 'Expected results to be present');
1001999
}
1002-
assert.ok(data.result, 'Expected results to be present');
10031000
// make sure the testID is found in the results
10041001
const indexOfTest = JSON.stringify(data).search(
10051002
'test_seg_fault.py::TestSegmentationFault::test_segfault',
@@ -1009,7 +1006,6 @@ suite('End to End Tests: test adapters', () => {
10091006
failureMsg = err ? (err as Error).toString() : '';
10101007
failureOccurred = true;
10111008
}
1012-
return Promise.resolve();
10131009
};
10141010

10151011
const testId = `${rootPathErrorWorkspace}/test_seg_fault.py::TestSegmentationFault::test_segfault`;
@@ -1091,19 +1087,17 @@ suite('End to End Tests: test adapters', () => {
10911087

10921088
// Wrap the _resolveExecution function to measure performance
10931089
const original_resolveExecution = resultResolver.resolveExecution.bind(resultResolver);
1094-
resultResolver.resolveExecution = async (payload, runInstance) => {
1090+
resultResolver.resolveExecution = (payload, runInstance) => {
10951091
const startTime = performance.now();
10961092
callCount++;
10971093

10981094
// Call the actual implementation
1099-
await original_resolveExecution(payload, runInstance);
1095+
original_resolveExecution(payload, runInstance);
11001096

11011097
const endTime = performance.now();
11021098
const callTime = endTime - startTime;
11031099
callTimes.push(callTime);
11041100
totalCallTime += callTime;
1105-
1106-
return Promise.resolve();
11071101
};
11081102

11091103
// ================================================================

0 commit comments

Comments
 (0)