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