mirror of
https://github.com/Microsoft/vscode
synced 2024-10-29 23:43:35 +00:00
testing: disallow moving from higher to lower terminal states
If a test is run multiple times during a single test run, don't allow to set the state back to a lower one, e.g. if the first test run failed but the second passed.
This commit is contained in:
parent
bd465c03ef
commit
8956522dd4
3 changed files with 36 additions and 3 deletions
|
@ -14,7 +14,7 @@ import { IComputedStateAccessor, refreshComputedState } from 'vs/workbench/contr
|
|||
import { IObservableValue, MutableObservableValue, staticObservableValue } from 'vs/workbench/contrib/testing/common/observableValue';
|
||||
import { IRichLocation, ISerializedTestResults, ITestItem, ITestMessage, ITestOutputMessage, ITestRunTask, ITestTaskState, ResolvedTestRunRequest, TestItemExpandState, TestMessageType, TestResultItem, TestResultState } from 'vs/workbench/contrib/testing/common/testCollection';
|
||||
import { TestCoverage } from 'vs/workbench/contrib/testing/common/testCoverage';
|
||||
import { maxPriority, statesInOrder } from 'vs/workbench/contrib/testing/common/testingStates';
|
||||
import { maxPriority, statesInOrder, terminalStatePriorities } from 'vs/workbench/contrib/testing/common/testingStates';
|
||||
|
||||
export interface ITestRunTaskResults extends ITestRunTask {
|
||||
/**
|
||||
|
@ -379,6 +379,17 @@ export class LiveTestResult implements ITestResult {
|
|||
}
|
||||
|
||||
const index = this.mustGetTaskIndex(taskId);
|
||||
|
||||
const oldTerminalStatePrio = terminalStatePriorities[entry.tasks[index].state];
|
||||
const newTerminalStatePrio = terminalStatePriorities[state];
|
||||
|
||||
// Ignore requests to set the state from one terminal state back to a
|
||||
// "lower" one, e.g. from failed back to passed:
|
||||
if (oldTerminalStatePrio !== undefined &&
|
||||
(newTerminalStatePrio === undefined || newTerminalStatePrio < oldTerminalStatePrio)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.fireUpdateAndRefresh(entry, index, state, duration);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,3 +59,15 @@ export const maxPriority = (...states: TestResultState[]) => {
|
|||
export const statesInOrder = Object.keys(statePriority).map(s => Number(s) as TestResultState).sort(cmpPriority);
|
||||
|
||||
export const isRunningState = (s: TestResultState) => s === TestResultState.Queued || s === TestResultState.Running;
|
||||
|
||||
/**
|
||||
* Some states are considered terminal; once these are set for a given test run, they
|
||||
* are not reset back to a non-terminal state, or to a terminal state with lower
|
||||
* priority.
|
||||
*/
|
||||
export const terminalStatePriorities: { [key in TestResultState]?: number } = {
|
||||
[TestResultState.Passed]: 0,
|
||||
[TestResultState.Skipped]: 1,
|
||||
[TestResultState.Failed]: 2,
|
||||
[TestResultState.Errored]: 3,
|
||||
};
|
||||
|
|
|
@ -144,14 +144,15 @@ suite('Workbench - Test Results Service', () => {
|
|||
|
||||
test('updateState', () => {
|
||||
changed.clear();
|
||||
r.updateState(new TestId(['ctrlId', 'id-a', 'id-aa']).toString(), 't', TestResultState.Running);
|
||||
const testId = new TestId(['ctrlId', 'id-a', 'id-aa']).toString();
|
||||
r.updateState(testId, 't', TestResultState.Running);
|
||||
assert.deepStrictEqual(r.counts, {
|
||||
...makeEmptyCounts(),
|
||||
[TestResultState.Unset]: 2,
|
||||
[TestResultState.Running]: 1,
|
||||
[TestResultState.Queued]: 1,
|
||||
});
|
||||
assert.deepStrictEqual(r.getStateById(new TestId(['ctrlId', 'id-a', 'id-aa']).toString())?.ownComputedState, TestResultState.Running);
|
||||
assert.deepStrictEqual(r.getStateById(testId)?.ownComputedState, TestResultState.Running);
|
||||
// update computed state:
|
||||
assert.deepStrictEqual(r.getStateById(tests.root.id)?.computedState, TestResultState.Running);
|
||||
assert.deepStrictEqual(getChangeSummary(), [
|
||||
|
@ -159,6 +160,15 @@ suite('Workbench - Test Results Service', () => {
|
|||
{ label: 'aa', reason: TestResultItemChangeReason.OwnStateChange },
|
||||
{ label: 'root', reason: TestResultItemChangeReason.ComputedStateChange },
|
||||
]);
|
||||
|
||||
r.updateState(testId, 't', TestResultState.Passed);
|
||||
assert.deepStrictEqual(r.getStateById(testId)?.ownComputedState, TestResultState.Passed);
|
||||
|
||||
r.updateState(testId, 't', TestResultState.Errored);
|
||||
assert.deepStrictEqual(r.getStateById(testId)?.ownComputedState, TestResultState.Errored);
|
||||
|
||||
r.updateState(testId, 't', TestResultState.Passed);
|
||||
assert.deepStrictEqual(r.getStateById(testId)?.ownComputedState, TestResultState.Errored);
|
||||
});
|
||||
|
||||
test('retire', () => {
|
||||
|
|
Loading…
Reference in a new issue