667175d350998493c79a7fb54b368e5cca685518
[WebKit-https.git] / Websites / perf.webkit.org / server-tests / privileged-api-create-test-group-tests.js
1 'use strict';
2
3 const assert = require('assert');
4
5 const MockData = require('./resources/mock-data.js');
6 const TestServer = require('./resources/test-server.js');
7 const TemporaryFile = require('./resources/temporary-file.js').TemporaryFile;
8 const addSlaveForReport = require('./resources/common-operations.js').addSlaveForReport;
9 const prepareServerTest = require('./resources/common-operations.js').prepareServerTest;
10
11 function createAnalysisTask(name)
12 {
13     const reportWithRevision = [{
14         "buildNumber": "124",
15         "buildTime": "2015-10-27T15:34:51",
16         "revisions": {
17             "WebKit": {
18                 "revision": "191622",
19                 "timestamp": '2015-10-27T11:36:56.878473Z',
20             },
21             "macOS": {
22                 "revision": "15A284",
23             }
24         },
25         "builderName": "someBuilder",
26         "slaveName": "someSlave",
27         "slavePassword": "somePassword",
28         "platform": "some platform",
29         "tests": {
30             "some test": {
31                 "metrics": {
32                     "Time": ["Arithmetic"],
33                 },
34                 "tests": {
35                     "test1": {
36                         "metrics": {"Time": { "current": [11] }},
37                     }
38                 }
39             },
40         }}];
41
42     const anotherReportWithRevision = [{
43         "buildNumber": "125",
44         "buildTime": "2015-10-27T17:27:41",
45         "revisions": {
46             "WebKit": {
47                 "revision": "191623",
48                 "timestamp": '2015-10-27T16:38:10.768995Z',
49             },
50             "macOS": {
51                 "revision": "15A284",
52             }
53         },
54         "builderName": "someBuilder",
55         "slaveName": "someSlave",
56         "slavePassword": "somePassword",
57         "platform": "some platform",
58         "tests": {
59             "some test": {
60                 "metrics": {
61                     "Time": ["Arithmetic"],
62                 },
63                 "tests": {
64                     "test1": {
65                         "metrics": {"Time": { "current": [12] }},
66                     }
67                 }
68             },
69         }}];
70
71     const db = TestServer.database();
72     const remote = TestServer.remoteAPI();
73     return addSlaveForReport(reportWithRevision[0]).then(() => {
74         return remote.postJSON('/api/report/', reportWithRevision);
75     }).then(() => {
76         return remote.postJSON('/api/report/', anotherReportWithRevision);
77     }).then((result) => {
78         return Manifest.fetch();
79     }).then(() => {
80         const test = Test.findByPath(['some test', 'test1']);
81         const platform = Platform.findByName('some platform');
82         return db.selectFirstRow('test_configurations', {metric: test.metrics()[0].id(), platform: platform.id()});
83     }).then((configRow) => {
84         return db.selectRows('test_runs', {config: configRow['id']});
85     }).then((testRuns) => {
86         assert.equal(testRuns.length, 2);
87         return PrivilegedAPI.sendRequest('create-analysis-task', {
88             name: name,
89             startRun: testRuns[0]['id'],
90             endRun: testRuns[1]['id'],
91         });
92     }).then((content) => content['taskId']);
93 }
94
95 function addTriggerableAndCreateTask(name)
96 {
97     const report = {
98         'slaveName': 'anotherSlave',
99         'slavePassword': 'anotherPassword',
100         'triggerable': 'build-webkit',
101         'configurations': [
102             {test: MockData.someTestId(), platform: MockData.somePlatformId()},
103             {test: MockData.someTestId(), platform: MockData.otherPlatformId()},
104         ],
105         'repositoryGroups': [
106             {name: 'webkit-only', repositories: [MockData.webkitRepositoryId()]},
107             {name: 'system-and-webkit', repositories: [MockData.macosRepositoryId(), MockData.webkitRepositoryId()]},
108         ]
109     };
110     return MockData.addMockData(TestServer.database()).then(() => {
111         return addSlaveForReport(report);
112     }).then(() => {
113         return TestServer.remoteAPI().postJSON('/api/update-triggerable/', report);
114     }).then(() => {
115         return createAnalysisTask(name);
116     });
117 }
118
119 describe('/privileged-api/create-test-group', function () {
120     prepareServerTest(this);
121     TemporaryFile.inject();
122
123     it('should return "InvalidName" on an empty request', () => {
124         return PrivilegedAPI.sendRequest('create-test-group', {}).then((content) => {
125             assert(false, 'should never be reached');
126         }, (error) => {
127             assert.equal(error, 'InvalidName');
128         });
129     });
130
131     it('should return "InvalidTask" when task is not specified', () => {
132         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', commitSets: [[1]]}).then((content) => {
133             assert(false, 'should never be reached');
134         }, (error) => {
135             assert.equal(error, 'InvalidTask');
136         });
137     });
138
139     it('should return "InvalidTask" when task is not a valid integer', () => {
140         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 'foo', commitSets: [[1]]}).then((content) => {
141             assert(false, 'should never be reached');
142         }, (error) => {
143             assert.equal(error, 'InvalidTask');
144         });
145     });
146
147     it('should return "InvalidCommitSets" when commit sets are not specified', () => {
148         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, repetitionCount: 1}).then((content) => {
149             assert(false, 'should never be reached');
150         }, (error) => {
151             assert.equal(error, 'InvalidCommitSets');
152         });
153     });
154
155     it('should return "InvalidCommitSets" when commit sets is empty', () => {
156         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, repetitionCount: 1, commitSets: {}}).then((content) => {
157             assert(false, 'should never be reached');
158         }, (error) => {
159             assert.equal(error, 'InvalidCommitSets');
160         });
161     });
162
163     it('should return "InvalidTask" when there is no matching task', () => {
164         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, repetitionCount: 1, commitSets: {'WebKit': []}}).then((content) => {
165             assert(false, 'should never be reached');
166         }, (error) => {
167             assert.equal(error, 'InvalidTask');
168         });
169     });
170
171     it('should return "InvalidRepetitionCount" when repetitionCount is not a valid integer', () => {
172         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, repetitionCount: 'foo', commitSets: {'WebKit': []}}).then((content) => {
173             assert(false, 'should never be reached');
174         }, (error) => {
175             assert.equal(error, 'InvalidRepetitionCount');
176         });
177     });
178
179     it('should return "InvalidRepetitionCount" when repetitionCount is a negative integer', () => {
180         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, repetitionCount: -5, commitSets: {'WebKit': []}}).then((content) => {
181             assert(false, 'should never be reached');
182         }, (error) => {
183             assert.equal(error, 'InvalidRepetitionCount');
184         });
185     });
186
187     it('should return "InvalidTask" when there is no matching task', () => {
188         return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: 1, commitSets: {'WebKit': []}}).then((content) => {
189             assert(false, 'should never be reached');
190         }, (error) => {
191             assert.equal(error, 'InvalidTask');
192         });
193     });
194
195     it('should return "TriggerableNotFoundForTask" when there is no matching triggerable', () => {
196         return createAnalysisTask('some task').then((taskId) => {
197             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'WebKit': []}}).then((content) => {
198                 assert(false, 'should never be reached');
199             }, (error) => {
200                 assert.equal(error, 'TriggerableNotFoundForTask');
201             });
202         });
203     });
204
205     it('should return "InvalidCommitSets" when each repository specifies zero revisions', () => {
206         return addTriggerableAndCreateTask('some task').then((taskId) => {
207             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'WebKit': []}}).then((content) => {
208                 assert(false, 'should never be reached');
209             }, (error) => {
210                 assert.equal(error, 'InvalidCommitSets');
211             });
212         });
213     });
214
215     it('should return "InvalidRevisionSets" when a revision set is empty', () => {
216         return addTriggerableAndCreateTask('some task').then((taskId) => {
217             const webkit = Repository.all().find((repository) => repository.name() == 'WebKit');
218             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, revisionSets: [{[webkit.id()]: '191622'}, {}]}).then((content) => {
219                 assert(false, 'should never be reached');
220             }, (error) => {
221                 assert.equal(error, 'InvalidRevisionSets');
222             });
223         });
224     });
225
226     it('should return "InvalidRevisionSets" when the number of revision sets is less than two', () => {
227         return addTriggerableAndCreateTask('some task').then((taskId) => {
228             const webkit = Repository.all().find((repository) => repository.name() == 'WebKit');
229             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, revisionSets: [{[webkit.id()]: '191622'}]}).then((content) => {
230                 assert(false, 'should never be reached');
231             }, (error) => {
232                 assert.equal(error, 'InvalidRevisionSets');
233             });
234         });
235     });
236
237     it('should return "RepositoryNotFound" when commit sets contains an invalid repository', () => {
238         return addTriggerableAndCreateTask('some task').then((taskId) => {
239             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'Foo': []}}).then((content) => {
240                 assert(false, 'should never be reached');
241             }, (error) => {
242                 assert.equal(error, 'RepositoryNotFound');
243             });
244         });
245     });
246
247     it('should return "RevisionNotFound" when commit sets contains an invalid revision', () => {
248         return addTriggerableAndCreateTask('some task').then((taskId) => {
249             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'WebKit': ['1']}}).then((content) => {
250                 assert(false, 'should never be reached');
251             }, (error) => {
252                 assert.equal(error, 'RevisionNotFound');
253             });
254         });
255     });
256
257     it('should return "RevisionNotFound" when revision sets contains an invalid revision', () => {
258         return addTriggerableAndCreateTask('some task').then((taskId) => {
259             const webkit = Repository.all().find((repository) => repository.name() == 'WebKit');
260             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, revisionSets: [{[webkit.id()]: '191622'}, {[webkit.id()]: '1'}]}).then((content) => {
261                 assert(false, 'should never be reached');
262             }, (error) => {
263                 assert.equal(error, 'RevisionNotFound');
264             });
265         });
266     });
267
268     it('should return "InvalidUploadedFile" when revision sets contains an invalid file ID', () => {
269         return addTriggerableAndCreateTask('some task').then((taskId) => {
270             const webkit = Repository.all().find((repository) => repository.name() == 'WebKit');
271             const revisionSets = [{[webkit.id()]: '191622', 'customRoots': ['1']}, {[webkit.id()]: '1'}];
272             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, revisionSets}).then((content) => {
273                 assert(false, 'should never be reached');
274             }, (error) => {
275                 assert.equal(error, 'InvalidUploadedFile');
276             });
277         });
278     });
279
280     it('should return "InvalidRepository" when a revision set uses a repository name instead of a repository id', () => {
281         return addTriggerableAndCreateTask('some task').then((taskId) => {
282             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, revisionSets: [{'WebKit': '191622'}, {}]}).then((content) => {
283                 assert(false, 'should never be reached');
284             }, (error) => {
285                 assert.equal(error, 'InvalidRepository');
286             });
287         });
288     });
289
290     it('should return "InvalidCommitSets" when commit sets contains an inconsistent number of revisions', () => {
291         return addTriggerableAndCreateTask('some task').then((taskId) => {
292             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'WebKit': ['191622', '191623'], 'macOS': ['15A284']}}).then((content) => {
293                 assert(false, 'should never be reached');
294             }, (error) => {
295                 assert.equal(error, 'InvalidCommitSets');
296             });
297         });
298     });
299
300     it('should create a test group from commitSets with the repetition count of one when repetitionCount is omitted', () => {
301         return addTriggerableAndCreateTask('some task').then((taskId) => {
302             let insertedGroupId;
303             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, commitSets: {'macOS': ['15A284', '15A284'], 'WebKit': ['191622', '191623']}}).then((content) => {
304                 insertedGroupId = content['testGroupId'];
305                 return TestGroup.fetchByTask(taskId);
306             }).then((testGroups) => {
307                 assert.equal(testGroups.length, 1);
308                 const group = testGroups[0];
309                 assert.equal(group.id(), insertedGroupId);
310                 assert.equal(group.repetitionCount(), 1);
311                 const requests = group.buildRequests();
312                 assert.equal(requests.length, 2);
313
314                 const macos = Repository.findById(MockData.macosRepositoryId());
315                 const webkit = Repository.findById(MockData.webkitRepositoryId());
316                 const set0 = requests[0].commitSet();
317                 const set1 = requests[1].commitSet();
318                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set0.repositories()), [webkit, macos]);
319                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set1.repositories()), [webkit, macos]);
320                 assert.equal(set0.revisionForRepository(macos), '15A284');
321                 assert.equal(set0.revisionForRepository(webkit), '191622');
322                 assert.equal(set1.revisionForRepository(macos), '15A284');
323                 assert.equal(set1.revisionForRepository(webkit), '191623');
324
325                 const repositoryGroup = requests[0].repositoryGroup();
326                 assert.equal(repositoryGroup.name(), 'system-and-webkit');
327                 assert.equal(requests[1].repositoryGroup(), repositoryGroup);
328                 assert(repositoryGroup.accepts(set0));
329                 assert(repositoryGroup.accepts(set1));
330             });
331         });
332     });
333
334     it('should create a test group from revisionSets with the repetition count of one when repetitionCount is omitted', () => {
335         let webkit;
336         return addTriggerableAndCreateTask('some task').then((taskId) => {
337             const webkit = Repository.findById(MockData.webkitRepositoryId());
338             const params = {name: 'test', task: taskId, revisionSets: [{[webkit.id()]: '191622'}, {[webkit.id()]: '191623'}]};
339             let insertedGroupId;
340             return PrivilegedAPI.sendRequest('create-test-group', params).then((content) => {
341                 insertedGroupId = content['testGroupId'];
342                 return TestGroup.fetchByTask(taskId);
343             }).then((testGroups) => {
344                 assert.equal(testGroups.length, 1);
345                 const group = testGroups[0];
346                 assert.equal(group.id(), insertedGroupId);
347                 assert.equal(group.repetitionCount(), 1);
348                 const requests = group.buildRequests();
349                 assert.equal(requests.length, 2);
350
351                 const set0 = requests[0].commitSet();
352                 const set1 = requests[1].commitSet();
353                 assert.deepEqual(set0.repositories(), [webkit]);
354                 assert.deepEqual(set1.repositories(), [webkit]);
355                 assert.equal(set0.revisionForRepository(webkit), '191622');
356                 assert.equal(set1.revisionForRepository(webkit), '191623');
357
358                 const repositoryGroup = requests[0].repositoryGroup();
359                 assert.equal(repositoryGroup.name(), 'webkit-only');
360                 assert.equal(repositoryGroup, requests[1].repositoryGroup());
361                 assert(repositoryGroup.accepts(set0));
362                 assert(repositoryGroup.accepts(set1));
363             });
364         });
365     });
366
367     it('should create a test group with the repetition count of two with two repositories', () => {
368         return addTriggerableAndCreateTask('some task').then((taskId) => {
369             let insertedGroupId;
370             return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, repetitionCount: 2,
371                 commitSets: {'WebKit': ['191622', '191623'], 'macOS': ['15A284', '15A284']}}).then((content) => {
372                 insertedGroupId = content['testGroupId'];
373                 return TestGroup.fetchByTask(taskId);
374             }).then((testGroups) => {
375                 assert.equal(testGroups.length, 1);
376                 const group = testGroups[0];
377                 assert.equal(group.id(), insertedGroupId);
378                 assert.equal(group.repetitionCount(), 2);
379                 const requests = group.buildRequests();
380                 assert.equal(requests.length, 4);
381                 const webkit = Repository.all().filter((repository) => repository.name() == 'WebKit')[0];
382                 const macos = Repository.all().filter((repository) => repository.name() == 'macOS')[0];
383
384                 const set0 = requests[0].commitSet();
385                 const set1 = requests[1].commitSet();
386                 assert.equal(requests[2].commitSet(), set0);
387                 assert.equal(requests[3].commitSet(), set1);
388                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set0.repositories()), [webkit, macos]);
389                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set1.repositories()), [webkit, macos]);
390                 assert.equal(set0.revisionForRepository(webkit), '191622');
391                 assert.equal(set0.revisionForRepository(macos), '15A284');
392                 assert.equal(set1.revisionForRepository(webkit), '191623');
393                 assert.equal(set1.revisionForRepository(macos), '15A284');
394                 assert.equal(set0.commitForRepository(macos), set1.commitForRepository(macos));
395
396                 const repositoryGroup = requests[0].repositoryGroup();
397                 assert.equal(repositoryGroup.name(), 'system-and-webkit');
398                 assert.equal(requests[1].repositoryGroup(), repositoryGroup);
399                 assert.equal(requests[2].repositoryGroup(), repositoryGroup);
400                 assert.equal(requests[3].repositoryGroup(), repositoryGroup);
401                 assert(repositoryGroup.accepts(set0));
402                 assert(repositoryGroup.accepts(set1));
403             });
404         });
405     });
406
407     it('should create a test group using different repository groups if needed', () => {
408         let webkit;
409         let macos;
410         return addTriggerableAndCreateTask('some task').then((taskId) => {
411             webkit = Repository.findById(MockData.webkitRepositoryId());
412             macos = Repository.findById(MockData.macosRepositoryId());
413             const params = {name: 'test', task: taskId, repetitionCount: 2,
414                 revisionSets: [{[macos.id()]: '15A284', [webkit.id()]: '191622'}, {[webkit.id()]: '191623'}]};
415             let insertedGroupId;
416             return PrivilegedAPI.sendRequest('create-test-group', params).then((content) => {
417                 insertedGroupId = content['testGroupId'];
418                 return TestGroup.fetchByTask(taskId);
419             }).then((testGroups) => {
420                 assert.equal(testGroups.length, 1);
421                 const group = testGroups[0];
422                 assert.equal(group.id(), insertedGroupId);
423                 assert.equal(group.repetitionCount(), 2);
424                 const requests = group.buildRequests();
425                 assert.equal(requests.length, 4);
426
427                 const set0 = requests[0].commitSet();
428                 const set1 = requests[1].commitSet();
429                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set0.repositories()), [webkit, macos]);
430                 assert.deepEqual(set1.repositories(), [webkit]);
431                 assert.equal(set0.revisionForRepository(webkit), '191622');
432                 assert.equal(set0.revisionForRepository(macos), '15A284');
433                 assert.equal(set1.revisionForRepository(webkit), '191623');
434                 assert.equal(set1.revisionForRepository(macos), null);
435
436                 const repositoryGroup0 = requests[0].repositoryGroup();
437                 assert.equal(repositoryGroup0.name(), 'system-and-webkit');
438                 assert.equal(repositoryGroup0, requests[2].repositoryGroup());
439                 assert(repositoryGroup0.accepts(set0));
440                 assert(!repositoryGroup0.accepts(set1));
441
442                 const repositoryGroup1 = requests[1].repositoryGroup();
443                 assert.equal(repositoryGroup1.name(), 'webkit-only');
444                 assert.equal(repositoryGroup1, requests[3].repositoryGroup());
445                 assert(!repositoryGroup1.accepts(set0));
446                 assert(repositoryGroup1.accepts(set1));
447             });
448         });
449     });
450
451     it('should create a test group with a custom root', () => {
452         return addTriggerableAndCreateTask('some task').then((taskId) => {
453             let insertedGroupId;
454             const webkit = Repository.all().filter((repository) => repository.name() == 'WebKit')[0];
455             const macos = Repository.all().filter((repository) => repository.name() == 'macOS')[0];
456             let uploadedFile;
457             return TemporaryFile.makeTemporaryFile('some.dat', 'some content').then((stream) => {
458                 return PrivilegedAPI.sendRequest('upload-file', {newFile: stream}, {useFormData: true});
459             }).then((response) => {
460                 uploadedFile = response['uploadedFile'];
461                 const revisionSets = [{[webkit.id()]: '191622', [macos.id()]: '15A284'},
462                     {[webkit.id()]: '191622', [macos.id()]: '15A284', 'customRoots': [uploadedFile['id']]}];
463                 return PrivilegedAPI.sendRequest('create-test-group', {name: 'test', task: taskId, repetitionCount: 2, revisionSets}).then((content) => {
464                     insertedGroupId = content['testGroupId'];
465                     return TestGroup.fetchByTask(taskId);
466                 });
467             }).then((testGroups) => {
468                 assert.equal(testGroups.length, 1);
469                 const group = testGroups[0];
470                 assert.equal(group.id(), insertedGroupId);
471                 assert.equal(group.repetitionCount(), 2);
472                 const requests = group.buildRequests();
473                 assert.equal(requests.length, 4);
474
475                 const set0 = requests[0].commitSet();
476                 const set1 = requests[1].commitSet();
477                 assert.equal(requests[2].commitSet(), set0);
478                 assert.equal(requests[3].commitSet(), set1);
479                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set0.repositories()), [webkit, macos]);
480                 assert.deepEqual(set0.customRoots(), []);
481                 assert.deepEqual(Repository.sortByNamePreferringOnesWithURL(set1.repositories()), [webkit, macos]);
482                 assert.deepEqual(set1.customRoots(), [UploadedFile.ensureSingleton(uploadedFile['id'], uploadedFile)]);
483                 assert.equal(set0.revisionForRepository(webkit), '191622');
484                 assert.equal(set0.revisionForRepository(webkit), set1.revisionForRepository(webkit));
485                 assert.equal(set0.commitForRepository(webkit), set1.commitForRepository(webkit));
486                 assert.equal(set0.revisionForRepository(macos), '15A284');
487                 assert.equal(set0.commitForRepository(macos), set1.commitForRepository(macos));
488                 assert.equal(set0.revisionForRepository(macos), set1.revisionForRepository(macos));
489                 assert(!set0.equals(set1));
490             });
491         });
492     });
493
494     it('should create a test group with an analysis task', () => {
495         let insertedGroupId;
496         let webkit;
497         return addTriggerableAndCreateTask('some task').then(() => {
498             webkit = Repository.all().filter((repository) => repository.name() == 'WebKit')[0];
499             const revisionSets = [{[webkit.id()]: '191622'}, {[webkit.id()]: '191623'}];
500             return PrivilegedAPI.sendRequest('create-test-group',
501                 {name: 'test', taskName: 'other task', platform: MockData.somePlatformId(), test: MockData.someTestId(), revisionSets});
502         }).then((result) => {
503             insertedGroupId = result['testGroupId'];
504             return Promise.all([AnalysisTask.fetchById(result['taskId']), TestGroup.fetchByTask(result['taskId'])]);
505         }).then((result) => {
506             const [analysisTask, testGroups] = result;
507
508             assert.equal(analysisTask.name(), 'other task');
509
510             assert.equal(testGroups.length, 1);
511             const group = testGroups[0];
512             assert.equal(group.id(), insertedGroupId);
513             assert.equal(group.repetitionCount(), 1);
514             const requests = group.buildRequests();
515             assert.equal(requests.length, 2);
516
517             const set0 = requests[0].commitSet();
518             const set1 = requests[1].commitSet();
519             assert.deepEqual(set0.repositories(), [webkit]);
520             assert.deepEqual(set0.customRoots(), []);
521             assert.deepEqual(set1.repositories(), [webkit]);
522             assert.deepEqual(set1.customRoots(), []);
523             assert.equal(set0.revisionForRepository(webkit), '191622');
524             assert.equal(set1.revisionForRepository(webkit), '191623');
525         });
526     });
527
528     it('should create a custom test group for an existing custom analysis task', () => {
529         let firstResult;
530         let secondResult;
531         let webkit;
532         let test = MockData.someTestId();
533         return addTriggerableAndCreateTask('some task').then(() => {
534             webkit = Repository.all().filter((repository) => repository.name() == 'WebKit')[0];
535             const revisionSets = [{[webkit.id()]: '191622'}, {[webkit.id()]: '191623'}];
536             return PrivilegedAPI.sendRequest('create-test-group',
537                 {name: 'test1', taskName: 'other task', platform: MockData.somePlatformId(), test, revisionSets});
538         }).then((result) => {
539             firstResult = result;
540             const revisionSets = [{[webkit.id()]: '191622'}, {[webkit.id()]: '192736'}];
541             return PrivilegedAPI.sendRequest('create-test-group',
542                 {name: 'test2', task: result['taskId'], platform: MockData.otherPlatformId(), test, revisionSets, repetitionCount: 2});
543         }).then((result) => {
544             secondResult = result;
545             assert.equal(firstResult['taskId'], secondResult['taskId']);
546             return Promise.all([AnalysisTask.fetchById(result['taskId']), TestGroup.fetchByTask(result['taskId'])]);
547         }).then((result) => {
548             const [analysisTask, testGroups] = result;
549
550             assert.equal(analysisTask.name(), 'other task');
551
552             assert.equal(testGroups.length, 2);
553             TestGroup.sortByName(testGroups);
554
555             assert.equal(testGroups[0].name(), 'test1');
556             assert.equal(testGroups[0].repetitionCount(), 1);
557             let requests = testGroups[0].buildRequests();
558             assert.equal(requests.length, 2);
559             let set0 = requests[0].commitSet();
560             let set1 = requests[1].commitSet();
561             assert.deepEqual(set0.repositories(), [webkit]);
562             assert.deepEqual(set0.customRoots(), []);
563             assert.deepEqual(set1.repositories(), [webkit]);
564             assert.deepEqual(set1.customRoots(), []);
565             assert.equal(set0.revisionForRepository(webkit), '191622');
566             assert.equal(set1.revisionForRepository(webkit), '191623');
567
568             assert.equal(testGroups[1].name(), 'test2');
569             assert.equal(testGroups[1].repetitionCount(), 2);
570             requests = testGroups[1].buildRequests();
571             assert.equal(requests.length, 4);
572             set0 = requests[0].commitSet();
573             set1 = requests[1].commitSet();
574             assert.deepEqual(requests[2].commitSet(), set0);
575             assert.deepEqual(requests[3].commitSet(), set1);
576             assert.deepEqual(set0.repositories(), [webkit]);
577             assert.deepEqual(set0.customRoots(), []);
578             assert.deepEqual(set1.repositories(), [webkit]);
579             assert.deepEqual(set1.customRoots(), []);
580             assert.equal(set0.revisionForRepository(webkit), '191622');
581             assert.equal(set1.revisionForRepository(webkit), '192736');
582         });
583     });
584
585 });