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