Skip to content

Commit 6d02f32

Browse files
Merge pull request #2172 from CodeNow/SAN-6094
SAN-6094 Don't run the tests if they have a valid state.
2 parents 3bbf364 + 88b0e76 commit 6d02f32

5 files changed

Lines changed: 151 additions & 27 deletions

File tree

client/directives/components/lists/branchTestList/branchTestListController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function BranchTestListController(
2424

2525
fetchInstanceTestHistory(BTLC.instance.attrs.id)
2626
.then(function(tests) {
27-
return calculateHistoricalTestResult(tests);
27+
return calculateHistoricalTestResult.addResults(tests);
2828
})
2929
.then(function(tests) {
3030
var testHash = {};

client/directives/components/lists/branchTestSelector/branchTestSelectorController.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function BranchTestSelectorController(
1010
keypather,
1111
loading,
1212
fetchCommitData,
13-
updateInstanceWithNewAcvData
13+
updateInstanceWithNewAcvData,
14+
calculateHistoricalTestResult
1415
) {
1516
var BTSC = this;
1617
BTSC.appCodeVersion = BTSC.instance.contextVersion.getMainAppCodeVersion();
@@ -37,7 +38,11 @@ function BranchTestSelectorController(
3738

3839
BTSC.selectCommit = function (commit) {
3940
BTSC.commit = commit;
40-
BTSC.updateInstance();
41+
42+
if (!calculateHistoricalTestResult.isValidState(BTSC.commit.test)) {
43+
BTSC.updateInstance();
44+
}
45+
4146
$scope.$emit('test-commit::selected', commit);
4247
$rootScope.$broadcast('close-popovers');
4348
};
@@ -58,6 +63,7 @@ function BranchTestSelectorController(
5863
};
5964

6065
BTSC.hasTest = function(commit) {
61-
return commit.test === 'passed' || commit.test === 'failed';
66+
return calculateHistoricalTestResult.isPassed(commit.test) ||
67+
calculateHistoricalTestResult.isFailed(commit.test);
6268
};
6369
}

client/services/calculateHistoricalTestResults.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,44 @@
33
require('app')
44
.factory('calculateHistoricalTestResult', calculateHistoricalTestResult);
55

6+
var PASSED = 'passed';
7+
var FAILED = 'failed';
8+
var UNKNOWN = 'unknown';
9+
var jesusBirthday = '0001-01-01T00:00:00Z';
10+
611
function calculateHistoricalTestResult(
712
keypather
813
) {
9-
return function (tests) {
10-
var TEST_STATES = {
11-
PASSED: 'passed',
12-
FAILED: 'failed',
13-
UNKNOWN: 'unknown'
14-
};
14+
return {
15+
isPassed: function(state) {
16+
return state === PASSED;
17+
},
18+
isFailed: function(state) {
19+
return state === FAILED;
20+
},
21+
isUnknown: function(state) {
22+
return state === UNKNOWN;
23+
},
24+
isValidState: function(state) {
25+
return state === PASSED || state === FAILED || state === UNKNOWN;
26+
},
27+
addResults: function (tests) {
28+
tests.forEach(function(test) {
29+
if (keypather.get(test, 'build.stop') !== jesusBirthday) {
30+
if (keypather.get(test, 'build.failed') || keypather.get(test, 'application.exitCode') > 0) {
31+
test.testState = FAILED;
32+
return;
33+
}
1534

16-
tests.forEach(function(test) {
17-
if (test && keypather.get(test, 'build.stop.valueOf()') !== new Date(0).valueOf()) {
18-
if (keypather.get(test, 'build.failed') || keypather.get(test, 'application.exitCode') > 0) {
19-
test.testState = TEST_STATES.FAILED;
20-
} else if (keypather.get(test,'application.exitCode') === 0 && keypather.get(test,'application.stop.valueOf()') !== new Date(0).valueOf()) {
21-
test.testState = TEST_STATES.PASSED;
35+
if (keypather.get(test,'application.exitCode') === 0 && keypather.get(test,'application.stop') !== jesusBirthday) {
36+
test.testState = PASSED;
37+
return;
38+
}
2239
}
23-
}
24-
25-
if (!test.testState) {
26-
test.testState = TEST_STATES.UNKNOWN;
27-
}
28-
});
40+
test.testState = UNKNOWN;
41+
});
2942

30-
return tests;
43+
return tests;
44+
}
3145
};
3246
}

test/unit/directives/components/lists/branchTestListController.unit.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe('BranchTestListController'.bold.underline.blue, function () {
1818
var newCommit;
1919
var appCodeVersion;
2020

21+
var jesusBirthday = '0001-01-01T00:00:00Z';
22+
2123
function initialize() {
2224
appCodeVersion = {
2325
attrs: {
@@ -74,7 +76,7 @@ describe('BranchTestListController'.bold.underline.blue, function () {
7476
{
7577
commitSha: '1',
7678
build: {
77-
stop: new Date(0),
79+
stop: jesusBirthday,
7880
failed: false
7981
}
8082
},
@@ -103,7 +105,7 @@ describe('BranchTestListController'.bold.underline.blue, function () {
103105
},
104106
application: {
105107
exitCode: 0,
106-
stop: new Date(0)
108+
stop: jesusBirthday
107109
}
108110
},
109111
{
@@ -178,13 +180,13 @@ describe('BranchTestListController'.bold.underline.blue, function () {
178180
$scope.$digest();
179181
// No test found
180182
expect(branch.commits.models[0].test).to.equal(null);
181-
// Test found but build exit time of epoch
183+
// Test found but build exit time of jesus birthday
182184
expect(branch.commits.models[1].test).to.equal('unknown');
183185
// Build failed is true
184186
expect(branch.commits.models[2].test).to.equal('failed');
185187
// // Build passed but exit code > 0
186188
expect(branch.commits.models[3].test).to.equal('failed');
187-
// Application stop is epoch
189+
// Application stop is jesus birthday
188190
expect(branch.commits.models[4].test).to.equal('unknown');
189191
expect(branch.commits.models[5].test).to.equal('passed');
190192
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
3+
describe('calculateHistoricalTestResult'.bold.underline.blue, function () {
4+
var calculateHistoricalTestResult;
5+
var keypather;
6+
var jesusBirthday = '0001-01-01T00:00:00Z';
7+
8+
function setup() {
9+
angular.mock.module('app');
10+
angular.mock.inject(function (
11+
_keypather_,
12+
_calculateHistoricalTestResult_
13+
) {
14+
calculateHistoricalTestResult = _calculateHistoricalTestResult_;
15+
keypather = _keypather_;
16+
});
17+
}
18+
19+
beforeEach(setup);
20+
21+
describe('calculateHistoricalTestResult', function () {
22+
it('addResults build stop epoch', function () {
23+
var tests = [{
24+
build: {
25+
stop: jesusBirthday,
26+
failed: false
27+
},
28+
application: {
29+
exitCode: 0,
30+
stop: new Date()
31+
}
32+
}];
33+
calculateHistoricalTestResult.addResults(tests);
34+
35+
expect(calculateHistoricalTestResult.isUnknown(tests[0].testState)).to.be.true;
36+
});
37+
38+
it('addResults build failed', function () {
39+
var tests = [{
40+
build: {
41+
stop: new Date(),
42+
failed: true
43+
},
44+
application: {
45+
exitCode: 0,
46+
stop: new Date()
47+
}
48+
}];
49+
calculateHistoricalTestResult.addResults(tests);
50+
51+
expect(calculateHistoricalTestResult.isFailed(tests[0].testState)).to.be.true;
52+
});
53+
54+
it('addResults exit code not 0', function () {
55+
var tests = [{
56+
build: {
57+
stop: new Date(),
58+
failed: false
59+
},
60+
application: {
61+
exitCode: 10,
62+
stop: new Date()
63+
}
64+
}];
65+
calculateHistoricalTestResult.addResults(tests);
66+
67+
expect(calculateHistoricalTestResult.isFailed(tests[0].testState)).to.be.true;
68+
});
69+
70+
it('addResults application stop epoch', function () {
71+
var tests = [{
72+
build: {
73+
stop: new Date(),
74+
failed: false
75+
},
76+
application: {
77+
exitCode: 0,
78+
stop: jesusBirthday
79+
}
80+
}];
81+
calculateHistoricalTestResult.addResults(tests);
82+
83+
expect(calculateHistoricalTestResult.isUnknown(tests[0].testState)).to.be.true;
84+
});
85+
86+
it('addResults passed', function () {
87+
var tests = [{
88+
build: {
89+
stop: new Date(),
90+
failed: false
91+
},
92+
application: {
93+
exitCode: 0,
94+
stop: new Date()
95+
}
96+
}];
97+
calculateHistoricalTestResult.addResults(tests);
98+
99+
expect(calculateHistoricalTestResult.isPassed(tests[0].testState)).to.be.true;
100+
});
101+
});
102+
});

0 commit comments

Comments
 (0)