-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathrun-estimator.spec.ts
More file actions
93 lines (82 loc) · 2.94 KB
/
run-estimator.spec.ts
File metadata and controls
93 lines (82 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
Result,
StageInfo,
} from "../../pipeline-graph-view/pipeline-graph/main/PipelineGraphModel.tsx";
import RunEstimator from "./run-estimator.ts";
const previous: StageInfo[] = [
makeStage("success", Result.success, 1000),
makeStage("failure", Result.failure, 2000),
];
function makeStage(name: string, state: Result, duration: number): StageInfo {
return {
name,
state,
totalDurationMillis: duration,
completePercent: 0,
title: "",
id: 0,
type: "STAGE",
children: [],
pauseDurationMillis: 0,
startTimeMillis: 0,
agent: "",
url: "",
};
}
describe("Run Estimator", () => {
let estimator: RunEstimator;
beforeEach(() => {
estimator = new RunEstimator(previous);
});
describe("Estimate Completion", () => {
const finishedStates = [
Result.success,
Result.unstable,
Result.failure,
Result.unknown,
Result.aborted,
Result.skipped,
Result.not_built,
];
const runningStates = [Result.running, Result.paused];
const others = Object.keys(Result)
.map((r) => Result[r as keyof typeof Result])
.filter((r) => !finishedStates.includes(r) && !runningStates.includes(r));
finishedStates.forEach((state) => {
describe(`Current Stage State = ${state}`, () => {
it(`should return 100% for current stage`, () => {
const stage = makeStage("finished", state, 1000);
expect(estimator.estimateCompletion(stage)).toEqual(100);
});
});
});
runningStates.forEach((state) => {
describe(`Current Stage State = ${state}`, () => {
it(`should return 0% when the current stage does not match a previous stage`, () => {
const stage = makeStage("unknown", state, 1000);
expect(estimator.estimateCompletion(stage)).toEqual(0);
});
it(`should return 99% when the current stage has been going longer than the previous stage`, () => {
const stage = makeStage("success", state, 1001);
expect(estimator.estimateCompletion(stage)).toEqual(99);
});
it(`should return 99% when the current stage has been going for the same time as the previous stage`, () => {
const stage = makeStage("success", state, 1000);
expect(estimator.estimateCompletion(stage)).toEqual(99);
});
it("should return the percentage complete when the current stage has been going for less time than the previous stage", () => {
const stage = makeStage("success", state, 50);
expect(estimator.estimateCompletion(stage)).toEqual(5);
});
});
});
others.forEach((state) => {
describe(`Current Stage State = ${state} (it is not a known finished or running state)`, () => {
it(`should return 0% for current stage`, () => {
const stage = makeStage("success", state, 1000);
expect(estimator.estimateCompletion(stage)).toEqual(0);
});
});
});
});
});