REGRESSION(r230960): Browser tests under TimeSeriesChart fetchMeasurementSets all...
[WebKit-https.git] / Websites / perf.webkit.org / unit-tests / test-groups-tests.js
1 'use strict';
2
3 const assert = require('assert');
4 require('../tools/js/v3-models.js');
5 const BrowserPrivilegedAPI = require('../public/v3/privileged-api.js').PrivilegedAPI;
6 const MockModels = require('./resources/mock-v3-models.js').MockModels;
7 const MockRemoteAPI = require('./resources/mock-remote-api.js').MockRemoteAPI;
8
9 function sampleTestGroup() {
10     return {
11         "testGroups": [{
12             "id": "2128",
13             "task": "1376",
14             "platform": "31",
15             "name": "Confirm",
16             "author": "rniwa",
17             "createdAt": 1458688514000,
18             "hidden": false,
19             "buildRequests": ["16985", "16986", "16987", "16988", "16989", "16990", "16991", "16992"],
20             "commitSets": ["4255", "4256"],
21         }],
22         "buildRequests": [{
23             "id": "16985",
24             "triggerable": "3",
25             "test": "844",
26             "platform": "31",
27             "testGroup": "2128",
28             "order": "0",
29             "commitSet": "4255",
30             "status": "pending",
31             "url": null,
32             "build": null,
33             "createdAt": 1458688514000
34         }, {
35             "id": "16986",
36             "triggerable": "3",
37             "test": "844",
38             "platform": "31",
39             "testGroup": "2128",
40             "order": "1",
41             "commitSet": "4256",
42             "status": "pending",
43             "url": null,
44             "build": null,
45             "createdAt": 1458688514000
46         },
47         {
48             "id": "16987",
49             "triggerable": "3",
50             "test": "844",
51             "platform": "31",
52             "testGroup": "2128",
53             "order": "2",
54             "commitSet": "4255",
55             "status": "pending",
56             "url": null,
57             "build": null,
58             "createdAt": 1458688514000
59         }, {
60             "id": "16988",
61             "triggerable": "3",
62             "test": "844",
63             "platform": "31",
64             "testGroup": "2128",
65             "order": "3",
66             "commitSet": "4256",
67             "status": "pending",
68             "url": null,
69             "build": null,
70             "createdAt": 1458688514000
71         }],
72         "commitSets": [{
73             "id": "4255",
74             "revisionItems": [{"commit": "87832"}, {"commit": "93116"}],
75             "customRoots": [],
76         }, {
77             "id": "4256",
78             "revisionItems": [{"commit": "87832"}, {"commit": "96336"}],
79             "customRoots": [],
80         }],
81         "commits": [{
82             "id": "87832",
83             "repository": "9",
84             "revision": "10.11 15A284",
85             "time": 0
86         }, {
87             "id": "93116",
88             "repository": "11",
89             "revision": "191622",
90             "time": 1445945816878
91         }, {
92             "id": "87832",
93             "repository": "9",
94             "revision": "10.11 15A284",
95             "time": 0
96         }, {
97             "id": "96336",
98             "repository": "11",
99             "revision": "192736",
100             "time": 1448225325650
101         }],
102         "uploadedFiles": [],
103         "status": "OK"
104     };
105 }
106
107 describe('TestGroup', function () {
108     MockModels.inject();
109
110     describe('fetchForTask', () => {
111         const requests = MockRemoteAPI.inject('https://perf.webkit.org', BrowserPrivilegedAPI);
112
113         it('should be able to fetch the list of test groups for the same task twice using cache', () => {
114             const fetchPromise = TestGroup.fetchForTask(1376);
115             assert.equal(requests.length, 1);
116             assert.equal(requests[0].method, 'GET');
117             assert.equal(requests[0].url, '/api/test-groups?task=1376');
118             requests[0].resolve(sampleTestGroup());
119
120             let assertTestGroups = (testGroups) => {
121                 assert.equal(testGroups.length, 1);
122                 assert.equal(testGroups[0].platform(), MockModels.elCapitan);
123                 const buildRequests = testGroups[0].buildRequests();
124                 assert.equal(buildRequests.length, 4);
125                 for (let request of buildRequests) {
126                     assert.equal(buildRequests[0].triggerable(), MockModels.triggerable);
127                     assert.equal(buildRequests[0].test(), MockModels.plt);
128                     assert.equal(buildRequests[0].platform(), MockModels.elCapitan);
129                 }
130             }
131
132             return fetchPromise.then((testGroups) => {
133                 assertTestGroups(testGroups);
134                 return TestGroup.fetchForTask(1376);
135             }).then((testGroups) => {
136                 assertTestGroups(testGroups);
137             });
138         });
139     });
140
141     describe('_createModelsFromFetchedTestGroups', function () {
142         it('should create test groups', function () {
143             var groups = TestGroup._createModelsFromFetchedTestGroups(sampleTestGroup());
144             assert.equal(groups.length, 1);
145
146             var group = groups[0];
147             assert.ok(group instanceof TestGroup);
148             assert.equal(group.id(), 2128);
149             assert.ok(group.createdAt() instanceof Date);
150             assert.equal(group.isHidden(), false);
151             assert.equal(+group.createdAt(), 1458688514000);
152             assert.equal(group.repetitionCount(), sampleTestGroup()['buildRequests'].length / 2);
153             assert.ok(group.hasPending());
154             assert.ok(!group.hasFinished());
155             assert.ok(!group.hasStarted());
156         });
157
158         it('should not create a new instance of TestGroup object if there is a matching entry', function () {
159             var firstObject = TestGroup._createModelsFromFetchedTestGroups(sampleTestGroup())[0];
160             assert.ok(firstObject instanceof TestGroup);
161             assert.equal(TestGroup._createModelsFromFetchedTestGroups(sampleTestGroup())[0], firstObject);
162         });
163
164         it('should create build requests for each group', function () {
165             var groups = TestGroup._createModelsFromFetchedTestGroups(sampleTestGroup());
166             assert.equal(groups.length, 1);
167             assert.equal(groups[0].buildRequests().length, sampleTestGroup()['buildRequests'].length);
168
169             var buildRequests = groups[0].buildRequests();
170             assert.equal(buildRequests[0].id(), 16985);
171             assert.equal(buildRequests[0].order(), 0);
172             assert.ok(!buildRequests[0].hasFinished());
173             assert.ok(!buildRequests[0].hasStarted());
174             assert.ok(buildRequests[0].isPending());
175             assert.equal(buildRequests[0].statusLabel(), 'Waiting');
176             assert.equal(buildRequests[0].buildId(), null);
177
178             assert.equal(buildRequests[1].id(), 16986);
179             assert.equal(buildRequests[1].order(), 1);
180             assert.ok(!buildRequests[1].hasFinished());
181             assert.ok(!buildRequests[1].hasStarted());
182             assert.ok(buildRequests[1].isPending());
183             assert.equal(buildRequests[1].statusLabel(), 'Waiting');
184             assert.equal(buildRequests[1].buildId(), null);
185         });
186
187         it('should create root sets for each group', function () {
188             var buildRequests = TestGroup._createModelsFromFetchedTestGroups(sampleTestGroup())[0].buildRequests();
189
190             var firstSet = buildRequests[0].commitSet();
191             assert.ok(firstSet instanceof CommitSet);
192             assert.equal(firstSet, buildRequests[2].commitSet());
193
194             var secondSet = buildRequests[1].commitSet();
195             assert.ok(secondSet instanceof CommitSet);
196             assert.equal(secondSet, buildRequests[3].commitSet());
197
198             assert.equal(firstSet.revisionForRepository(MockModels.webkit), '191622');
199             var firstWebKitCommit = firstSet.commitForRepository(MockModels.webkit);
200             assert.ok(firstWebKitCommit instanceof CommitLog);
201             assert.ok(firstWebKitCommit, buildRequests[2].commitSet().commitForRepository(MockModels.webkit));
202             assert.ok(firstWebKitCommit.repository(), MockModels.webkit);
203             assert.ok(firstWebKitCommit.revision(), '191622');
204             assert.ok(firstWebKitCommit.time() instanceof Date);
205             assert.ok(+firstWebKitCommit.time(), 1445945816878);
206
207             assert.equal(secondSet.revisionForRepository(MockModels.webkit), '192736');
208             var secondWebKitCommit = secondSet.commitForRepository(MockModels.webkit);
209             assert.ok(secondWebKitCommit instanceof CommitLog);
210             assert.ok(secondWebKitCommit, buildRequests[3].commitSet().commitForRepository(MockModels.webkit));
211             assert.ok(secondWebKitCommit.repository(), MockModels.webkit);
212             assert.ok(secondWebKitCommit.revision(), '192736');
213             assert.ok(secondWebKitCommit.time() instanceof Date);
214             assert.ok(+secondWebKitCommit.time(), 1445945816878);
215
216             assert.equal(firstSet.revisionForRepository(MockModels.osx), '10.11 15A284');
217             var osxCommit = firstSet.commitForRepository(MockModels.osx);
218             assert.ok(osxCommit instanceof CommitLog);
219             assert.equal(osxCommit, buildRequests[1].commitSet().commitForRepository(MockModels.osx));
220             assert.equal(osxCommit, buildRequests[2].commitSet().commitForRepository(MockModels.osx));
221             assert.equal(osxCommit, buildRequests[3].commitSet().commitForRepository(MockModels.osx));
222             assert.ok(osxCommit.repository(), MockModels.osx);
223             assert.ok(osxCommit.revision(), '10.11 15A284');
224         });
225     });
226
227     function testGroupWithStatusList(list) {
228         var data = sampleTestGroup();
229         data.buildRequests[0].status = list[0];
230         data.buildRequests[1].status = list[1];
231         data.buildRequests[2].status = list[2];
232         data.buildRequests[3].status = list[3];
233         return TestGroup._createModelsFromFetchedTestGroups(data)[0];
234     }
235
236     describe('hasFinished', function () {
237         it('should return true if all build requests have completed', function () {
238             assert.ok(testGroupWithStatusList(['completed', 'completed', 'completed', 'completed']).hasFinished());
239         });
240
241         it('should return true if all build requests have failed', function () {
242             assert.ok(testGroupWithStatusList(['failed', 'failed', 'failed', 'failed']).hasFinished());
243         });
244
245         it('should return true if all build requests have been canceled', function () {
246             assert.ok(testGroupWithStatusList(['canceled', 'canceled', 'canceled', 'canceled']).hasFinished());
247         });
248
249         it('should return true if all build requests have completed or failed', function () {
250             assert.ok(testGroupWithStatusList(['failed', 'completed', 'failed', 'failed']).hasFinished());
251         });
252
253         it('should return true if all build requests have completed, failed, or canceled', function () {
254             assert.ok(testGroupWithStatusList(['failed', 'completed', 'canceled', 'canceled']).hasFinished());
255         });
256
257         it('should return false if all build requests are pending', function () {
258             assert.ok(!testGroupWithStatusList(['pending', 'pending', 'pending', 'pending']).hasFinished());
259         });
260
261         it('should return false if some build requests are pending', function () {
262             assert.ok(!testGroupWithStatusList(['completed', 'completed', 'completed', 'pending']).hasFinished());
263         });
264
265         it('should return false if some build requests are scheduled', function () {
266             assert.ok(!testGroupWithStatusList(['completed', 'completed', 'completed', 'scheduled']).hasFinished());
267         });
268
269         it('should return false if some build requests are running', function () {
270             assert.ok(!testGroupWithStatusList(['completed', 'canceled', 'completed', 'running']).hasFinished());
271         });
272     });
273
274     describe('hasStarted', function () {
275         it('should return true if all build requests have completed', function () {
276             assert.ok(testGroupWithStatusList(['completed', 'completed', 'completed', 'completed']).hasStarted());
277         });
278
279         it('should return true if all build requests have failed', function () {
280             assert.ok(testGroupWithStatusList(['failed', 'failed', 'failed', 'failed']).hasStarted());
281         });
282
283         it('should return true if all build requests have been canceled', function () {
284             assert.ok(testGroupWithStatusList(['canceled', 'canceled', 'canceled', 'canceled']).hasStarted());
285         });
286
287         it('should return true if all build requests have completed or failed', function () {
288             assert.ok(testGroupWithStatusList(['failed', 'completed', 'failed', 'failed']).hasStarted());
289         });
290
291         it('should return true if all build requests have completed, failed, or cancled', function () {
292             assert.ok(testGroupWithStatusList(['failed', 'completed', 'canceled', 'canceled']).hasStarted());
293         });
294
295         it('should return false if all build requests are pending', function () {
296             assert.ok(!testGroupWithStatusList(['pending', 'pending', 'pending', 'pending']).hasStarted());
297         });
298
299         it('should return true if some build requests have completed', function () {
300             assert.ok(testGroupWithStatusList(['completed', 'pending', 'pending', 'pending']).hasStarted());
301         });
302
303         it('should return true if some build requests are scheduled', function () {
304             assert.ok(testGroupWithStatusList(['scheduled', 'pending', 'pending', 'pending']).hasStarted());
305         });
306
307         it('should return true if some build requests are running', function () {
308             assert.ok(testGroupWithStatusList(['running', 'pending', 'pending', 'pending']).hasStarted());
309         });
310     });
311
312     describe('hasPending', function () {
313         it('should return false if all build requests have completed', function () {
314             assert.ok(!testGroupWithStatusList(['completed', 'completed', 'completed', 'completed']).hasPending());
315         });
316
317         it('should return false if all build requests have failed', function () {
318             assert.ok(!testGroupWithStatusList(['failed', 'failed', 'failed', 'failed']).hasPending());
319         });
320
321         it('should return false if all build requests have been canceled', function () {
322             assert.ok(!testGroupWithStatusList(['canceled', 'canceled', 'canceled', 'canceled']).hasPending());
323         });
324
325         it('should return false if all build requests have completed or failed', function () {
326             assert.ok(!testGroupWithStatusList(['failed', 'completed', 'failed', 'failed']).hasPending());
327         });
328
329         it('should return false if all build requests have completed, failed, or cancled', function () {
330             assert.ok(!testGroupWithStatusList(['failed', 'completed', 'canceled', 'canceled']).hasPending());
331         });
332
333         it('should return true if all build requests are pending', function () {
334             assert.ok(testGroupWithStatusList(['pending', 'pending', 'pending', 'pending']).hasPending());
335         });
336
337         it('should return true if some build requests are pending', function () {
338             assert.ok(testGroupWithStatusList(['completed', 'failed', 'canceled', 'pending']).hasPending());
339         });
340
341         it('should return false if some build requests are scheduled and others have completed', function () {
342             assert.ok(!testGroupWithStatusList(['completed', 'completed', 'completed', 'scheduled']).hasPending());
343         });
344     });
345
346 });