c737bb6d6f61271a6dbea80e5e2e8e960359ec37
[WebKit.git] / Websites / perf.webkit.org / server-tests / tools-sync-buildbot-integration-tests.js
1 'use strict';
2
3 const assert = require('assert');
4
5 require('../tools/js/v3-models.js');
6
7 const BuildbotTriggerable = require('../tools/js/buildbot-triggerable.js').BuildbotTriggerable;
8 const MockData = require('./resources/mock-data.js');
9 const MockLogger = require('./resources/mock-logger.js').MockLogger;
10 const MockRemoteAPI = require('../unit-tests/resources/mock-remote-api.js').MockRemoteAPI;
11 const TestServer = require('./resources/test-server.js');
12 const TemporaryFile = require('./resources/temporary-file.js').TemporaryFile;
13 const addSlaveForReport = require('./resources/common-operations.js').addSlaveForReport;
14 const prepareServerTest = require('./resources/common-operations.js').prepareServerTest;
15
16 const configWithOneTesterTwoBuilders = {
17     triggerableName: 'build-webkit',
18     lookbackCount: 2,
19     buildRequestArgument: 'build-request-id',
20     slaveName: 'sync-slave',
21     slavePassword: 'password',
22     repositoryGroups: {
23         'webkit': {
24             repositories: {'WebKit': {acceptsPatch: true}},
25             testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
26             buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
27                 'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
28                 'build-wk': {'ifRepositorySet': ['WebKit'], 'value': true},
29                 'owned-commits': {'ownedRevisions': 'WebKit'}},
30             acceptsRoots: true,
31         }
32     },
33     types: {
34         'some': {
35             test: ['some test'],
36             properties: {'test': 'some-test'},
37         }
38     },
39     builders: {
40         'builder-1': {
41             builder: 'some tester',
42             properties: {forcescheduler: 'force-ab-tests'},
43         },
44         'builder-2': {
45             builder: 'some builder',
46             properties: {forcescheduler: 'force-ab-builds'},
47         },
48         'builder-3': {
49             builder: 'other builder',
50             properties: {forcescheduler: 'force-ab-builds'},
51         },
52     },
53     buildConfigurations: [
54         {platforms: ['some platform'], builders: ['builder-2', 'builder-3']},
55     ],
56     testConfigurations: [
57         {types: ['some'], platforms: ['some platform'], builders: ['builder-1']},
58     ],
59 };
60
61 const configWithPlatformName = {
62     triggerableName: 'build-webkit',
63     lookbackCount: 2,
64     buildRequestArgument: 'build-request-id',
65     slaveName: 'sync-slave',
66     slavePassword: 'password',
67     platformArgument: 'platform-name',
68     repositoryGroups: {
69         'webkit': {
70             repositories: {'WebKit': {acceptsPatch: true}},
71             testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
72             buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
73                 'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
74                 'build-wk': {'ifRepositorySet': ['WebKit'], 'value': true},
75                 'owned-commits': {'ownedRevisions': 'WebKit'}},
76             acceptsRoots: true,
77         }
78     },
79     types: {
80         'some': {
81             test: ['some test'],
82             properties: {'test': 'some-test'},
83         }
84     },
85     builders: {
86         'builder-1': {
87             builder: 'some tester',
88             properties: {forcescheduler: 'force-ab-tests'},
89         },
90         'builder-2': {
91             builder: 'some builder',
92             properties: {forcescheduler: 'force-ab-builds'},
93         },
94         'builder-3': {
95             builder: 'other builder',
96             properties: {forcescheduler: 'force-ab-builds'},
97         },
98     },
99     buildConfigurations: [
100         {platforms: ['some platform'], builders: ['builder-2', 'builder-3']},
101     ],
102     testConfigurations: [
103         {types: ['some'], platforms: ['some platform'], builders: ['builder-1']},
104     ],
105 };
106
107 const configWithTwoTesters = {
108     triggerableName: 'build-webkit',
109     lookbackCount: 2,
110     buildRequestArgument: 'build-request-id',
111     slaveName: 'sync-slave',
112     slavePassword: 'password',
113     repositoryGroups: {
114         'webkit': {
115             repositories: {'WebKit': {acceptsPatch: true}},
116             testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
117             buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
118                 'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
119                 'build-wk': {'ifRepositorySet': ['WebKit'], 'value': true},
120                 'owned-commits': {'ownedRevisions': 'WebKit'}},
121             acceptsRoots: true,
122         }
123     },
124     types: {
125         'some': {
126             test: ['some test'],
127             properties: {'test': 'some-test'},
128         }
129     },
130     builders: {
131         'builder-1': {
132             builder: 'some tester',
133             properties: {forcescheduler: 'force-ab-tests'},
134         },
135         'builder-2': {
136             builder: 'another tester',
137             properties: {forcescheduler: 'force-ab-builds'},
138         },
139     },
140     testConfigurations: [
141         {types: ['some'], platforms: ['some platform'], builders: ['builder-1', 'builder-2']},
142     ]
143 };
144
145 function assertAndResolveRequest(request, method, url, contentToResolve)
146 {
147     assert.equal(request.method, method);
148     assert.equal(request.url, url);
149     request.resolve(contentToResolve);
150 }
151
152 function createTriggerable(config = configWithOneTesterTwoBuilders)
153 {
154     let triggerable;
155     return MockData.addMockConfiguration(TestServer.database()).then(() => {
156         return Manifest.fetch();
157     }).then(() => {
158         triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, {name: 'sync-slave', password: 'password'}, new MockLogger);
159         const syncPromise = triggerable.initSyncers().then(() => triggerable.updateTriggerable());
160         assertAndResolveRequest(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
161         MockRemoteAPI.reset();
162         return syncPromise;
163     }).then(() => Manifest.fetch()).then(() => {
164         return new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, {name: 'sync-slave', password: 'password'}, new MockLogger);
165     });
166 }
167
168 function createTestGroup(task_name='custom task') {
169     const someTest = Test.findById(MockData.someTestId());
170     const webkit = Repository.findById(MockData.webkitRepositoryId());
171     const set1 = new CustomCommitSet;
172     set1.setRevisionForRepository(webkit, '191622');
173     const set2 = new CustomCommitSet;
174     set2.setRevisionForRepository(webkit, '192736');
175     return TestGroup.createWithTask('custom task', Platform.findById(MockData.somePlatformId()), someTest, 'some group', 2, [set1, set2]).then((task) => {
176         return TestGroup.findAllByTask(task.id())[0];
177     });
178 }
179
180 function createTestGroupWihPatch()
181 {
182     return TemporaryFile.makeTemporaryFile('patch.dat', 'patch file').then((patchFile) => {
183         return UploadedFile.uploadFile(patchFile);
184     }).then((patchFile) => {
185         const someTest = Test.findById(MockData.someTestId());
186         const webkit = Repository.findById(MockData.webkitRepositoryId());
187         const set1 = new CustomCommitSet;
188         set1.setRevisionForRepository(webkit, '191622', patchFile);
189         const set2 = new CustomCommitSet;
190         set2.setRevisionForRepository(webkit, '191622');
191         return TestGroup.createWithTask('custom task', Platform.findById(MockData.somePlatformId()), someTest, 'some group', 2, [set1, set2]);
192     }).then((task) => {
193         return TestGroup.findAllByTask(task.id())[0];
194     })
195 }
196
197 function createTestGroupWihOwnedCommit()
198 {
199     const someTest = Test.findById(MockData.someTestId());
200     const webkit = Repository.findById(MockData.webkitRepositoryId());
201     const ownedSJC = Repository.findById(MockData.ownedJSCRepositoryId());
202     const set1 = new CustomCommitSet;
203     set1.setRevisionForRepository(webkit, '191622');
204     set1.setRevisionForRepository(ownedSJC, 'owned-jsc-6161', null, '191622');
205     const set2 = new CustomCommitSet;
206     set2.setRevisionForRepository(webkit, '192736');
207     set2.setRevisionForRepository(ownedSJC, 'owned-jsc-9191', null, '192736');
208     return TestGroup.createWithTask('custom task', Platform.findById(MockData.somePlatformId()), someTest, 'some group', 2, [set1, set2]).then((task) => {
209         return TestGroup.findAllByTask(task.id())[0];
210     });
211 }
212
213 function uploadRoot(buildRequestId, buildNumber, repositoryList = ["WebKit"], buildTime = '2017-05-10T02:54:08.666')
214 {
215     return TemporaryFile.makeTemporaryFile(`root${buildNumber}.dat`, `root for build ${buildNumber} and repository list at ${buildTime}`).then((rootFile) => {
216         return TestServer.remoteAPI().postFormData('/api/upload-root/', {
217             slaveName: 'sync-slave',
218             slavePassword: 'password',
219             builderName: 'some builder',
220             buildNumber: buildNumber,
221             buildTime: buildTime,
222             buildRequest: buildRequestId,
223             rootFile,
224             repositoryList: JSON.stringify(repositoryList),
225         });
226     });
227 }
228
229 describe('sync-buildbot', function () {
230     prepareServerTest(this);
231     TemporaryFile.inject();
232
233     beforeEach(() => {
234         MockRemoteAPI.reset('http://build.webkit.org');
235     });
236
237
238     it('should not schedule on another builder if the build was scheduled on one builder before', () => {
239         const requests = MockRemoteAPI.requests;
240         let firstTestGroup;
241         let secondTestGroup;
242         let syncPromise;
243         let triggerable;
244         let taskId = null;
245         let anotherTaskId = null;
246         return createTriggerable(configWithTwoTesters).then((newTriggerable) => {
247             triggerable = newTriggerable;
248             return Promise.all([createTestGroup(), createTestGroup('another custom task')]);
249         }).then((testGroups) => {
250             firstTestGroup = testGroups[0];
251             secondTestGroup = testGroups[1];
252             taskId = firstTestGroup.task().id();
253             anotherTaskId = secondTestGroup.task().id();
254             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
255             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
256             MockRemoteAPI.reset();
257             return MockRemoteAPI.waitForRequest();
258         }).then(() => {
259             assert.equal(requests.length, 2);
260             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', [MockData.pendingBuild({builder: 'some tester', buildRequestId: 5})]);
261             assertAndResolveRequest(requests[1], 'GET', '/json/builders/another%20tester/pendingBuilds', []);
262             return MockRemoteAPI.waitForRequest();
263         }).then(() => {
264             assert.equal(requests.length, 4);
265             assertAndResolveRequest(requests[2], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {
266                 [-1]: MockData.runningBuild({builder: 'some tester', buildRequestId: 1})});
267             assertAndResolveRequest(requests[3], 'GET', '/json/builders/another%20tester/builds/?select=-1&select=-2', {});
268             return MockRemoteAPI.waitForRequest();
269         }).then(() => {
270             assert.equal(requests.length, 6);
271             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
272             assertAndResolveRequest(requests[5], 'GET', '/json/builders/another%20tester/pendingBuilds',[]);
273             return MockRemoteAPI.waitForRequest();
274         }).then(() => {
275             assert.equal(requests.length, 8);
276             assertAndResolveRequest(requests[6], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {
277                 [-1]: MockData.runningBuild({builder: 'some tester', buildRequestId: 5}),
278                 [-2]: MockData.finishedBuild({builder: 'some tester', buildRequestId: 1})
279             });
280             assertAndResolveRequest(requests[7], 'GET', '/json/builders/another%20tester/builds/?select=-1&select=-2', {});
281             return syncPromise;
282         }).then(() => {
283             return TestGroup.fetchForTask(taskId, true);
284         }).then((testGroups) => {
285             assert.equal(testGroups.length, 1);
286             const testGroup = testGroups[0];
287             const webkit = Repository.findById(MockData.webkitRepositoryId());
288
289             const buildRequest = testGroup.buildRequests()[0];
290             assert.equal(testGroup.buildRequests().length, 4);
291             assert(!buildRequest.isBuild());
292             assert(buildRequest.isTest());
293
294             const commitSet = buildRequest.commitSet();
295             assert.equal(commitSet.revisionForRepository(webkit), '191622');
296
297             const otherBuildRequest = testGroup.buildRequests()[1];
298             assert(!otherBuildRequest.isBuild());
299             assert(otherBuildRequest.isTest());
300
301             const otherCommitSet = otherBuildRequest.commitSet();
302             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
303
304             return TestGroup.fetchForTask(anotherTaskId, true);
305         }).then((testGroups) => {
306             assert.equal(testGroups.length, 1);
307             const testGroup = testGroups[0];
308             const webkit = Repository.findById(MockData.webkitRepositoryId());
309
310             const buildRequest = testGroup.buildRequests()[0];
311             assert.equal(testGroup.buildRequests().length, 4);
312             assert(!buildRequest.isBuild());
313             assert(buildRequest.isTest());
314
315             const commitSet = buildRequest.commitSet();
316             assert.equal(commitSet.revisionForRepository(webkit), '191622');
317
318             const otherBuildRequest = testGroup.buildRequests()[1];
319             assert(!otherBuildRequest.isBuild());
320             assert(otherBuildRequest.isTest());
321
322             const otherCommitSet = otherBuildRequest.commitSet();
323             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
324         });
325     });
326
327     it('should schedule a build to build a patch', () => {
328         const requests = MockRemoteAPI.requests;
329         let triggerable;
330         let taskId = null;
331         let syncPromise;
332         return createTriggerable().then((newTriggerable) => {
333             triggerable = newTriggerable;
334             return createTestGroupWihPatch();
335         }).then((testGroup) => {
336             taskId = testGroup.task().id();
337             const webkit = Repository.findById(MockData.webkitRepositoryId());
338             assert.equal(testGroup.buildRequests().length, 6);
339
340             const buildRequest = testGroup.buildRequests()[0];
341             assert(buildRequest.isBuild());
342             assert(!buildRequest.isTest());
343             assert.equal(buildRequest.statusLabel(), 'Waiting');
344             assert.equal(buildRequest.statusUrl(), null);
345             assert.equal(buildRequest.buildId(), null);
346
347             const commitSet = buildRequest.commitSet();
348             assert.equal(commitSet.revisionForRepository(webkit), '191622');
349             const webkitPatch = commitSet.patchForRepository(webkit);
350             assert(webkitPatch instanceof UploadedFile);
351             assert.equal(webkitPatch.filename(), 'patch.dat');
352             assert.equal(commitSet.rootForRepository(webkit), null);
353             assert.deepEqual(commitSet.allRootFiles(), []);
354
355             const otherBuildRequest = testGroup.buildRequests()[1];
356             assert(otherBuildRequest.isBuild());
357             assert(!otherBuildRequest.isTest());
358             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
359             assert.equal(otherBuildRequest.statusUrl(), null);
360             assert.equal(otherBuildRequest.buildId(), null);
361
362             const otherCommitSet = otherBuildRequest.commitSet();
363             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
364             assert.equal(otherCommitSet.patchForRepository(webkit), null);
365             assert.equal(otherCommitSet.rootForRepository(webkit), null);
366             assert.deepEqual(otherCommitSet.allRootFiles(), []);
367
368             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
369             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
370             MockRemoteAPI.reset();
371             return MockRemoteAPI.waitForRequest();
372         }).then(() => {
373             assert.equal(requests.length, 3);
374             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
375             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
376             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
377             return MockRemoteAPI.waitForRequest();
378         }).then(() => {
379             assert.equal(requests.length, 6);
380             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
381             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
382             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
383             return MockRemoteAPI.waitForRequest();
384         }).then(() => {
385             assert.equal(requests.length, 7);
386             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
387             assert.deepEqual(requests[6].data, {'wk': '191622', 'wk-patch': RemoteAPI.url('/api/uploaded-file/1.dat'),
388                 'build-request-id': '1', 'forcescheduler': 'force-ab-builds', 'checkbox': 'build-wk', 'build-wk': true});
389             return MockRemoteAPI.waitForRequest();
390         }).then(() => {
391             assert.equal(requests.length, 10);
392             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
393             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds',
394                 [MockData.pendingBuild({builder: 'some builder', buildRequestId: 1})]);
395             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
396             return MockRemoteAPI.waitForRequest();
397         }).then(() => {
398             assert.equal(requests.length, 13);
399             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
400             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
401                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 1})
402             });
403             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
404             return syncPromise;
405         }).then(() => {
406             return TestGroup.fetchForTask(taskId, true);
407         }).then((testGroups) => {
408             assert.equal(testGroups.length, 1);
409             const testGroup = testGroups[0];
410             const webkit = Repository.findById(MockData.webkitRepositoryId());
411             assert.equal(testGroup.buildRequests().length, 6);
412
413             const buildRequest = testGroup.buildRequests()[0];
414             assert(buildRequest.isBuild());
415             assert(!buildRequest.isTest());
416             assert.equal(buildRequest.statusLabel(), 'Running');
417             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
418             assert.equal(buildRequest.buildId(), null);
419
420             const commitSet = buildRequest.commitSet();
421             assert.equal(commitSet.revisionForRepository(webkit), '191622');
422             const webkitPatch = commitSet.patchForRepository(webkit);
423             assert(webkitPatch instanceof UploadedFile);
424             assert.equal(webkitPatch.filename(), 'patch.dat');
425             assert.equal(commitSet.rootForRepository(webkit), null);
426             assert.deepEqual(commitSet.allRootFiles(), []);
427
428             const otherBuildRequest = testGroup.buildRequests()[1];
429             assert(otherBuildRequest.isBuild());
430             assert(!otherBuildRequest.isTest());
431             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
432             assert.equal(otherBuildRequest.statusUrl(), null);
433             assert.equal(otherBuildRequest.buildId(), null);
434
435             const otherCommitSet = otherBuildRequest.commitSet();
436             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
437             assert.equal(otherCommitSet.patchForRepository(webkit), null);
438             assert.equal(otherCommitSet.rootForRepository(webkit), null);
439             assert.deepEqual(otherCommitSet.allRootFiles(), []);
440
441             return uploadRoot(buildRequest.id(), 123);
442         }).then(() => {
443             return TestGroup.fetchForTask(taskId, true);
444         }).then((testGroups) => {
445             assert.equal(testGroups.length, 1);
446             const testGroup = testGroups[0];
447             const webkit = Repository.findById(MockData.webkitRepositoryId());
448             assert.equal(testGroup.buildRequests().length, 6);
449
450             const buildRequest = testGroup.buildRequests()[0];
451             assert(buildRequest.isBuild());
452             assert(!buildRequest.isTest());
453             assert.equal(buildRequest.statusLabel(), 'Completed');
454             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
455             assert.notEqual(buildRequest.buildId(), null);
456
457             const commitSet = buildRequest.commitSet();
458             assert.equal(commitSet.revisionForRepository(webkit), '191622');
459             const webkitPatch = commitSet.patchForRepository(webkit);
460             assert(webkitPatch instanceof UploadedFile);
461             assert.equal(webkitPatch.filename(), 'patch.dat');
462             const webkitRoot = commitSet.rootForRepository(webkit);
463             assert(webkitRoot instanceof UploadedFile);
464             assert.equal(webkitRoot.filename(), 'root123.dat');
465             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
466
467             const otherBuildRequest = testGroup.buildRequests()[1];
468             assert(otherBuildRequest.isBuild());
469             assert(!otherBuildRequest.isTest());
470             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
471             assert.equal(otherBuildRequest.statusUrl(), null);
472             assert.equal(otherBuildRequest.buildId(), null);
473
474             const otherCommitSet = otherBuildRequest.commitSet();
475             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
476             assert.equal(otherCommitSet.patchForRepository(webkit), null);
477             assert.equal(otherCommitSet.rootForRepository(webkit), null);
478             assert.deepEqual(otherCommitSet.allRootFiles(), []);
479
480             MockRemoteAPI.reset();
481             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
482             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
483             MockRemoteAPI.reset();
484             return MockRemoteAPI.waitForRequest();
485         }).then(() => {
486             assert.equal(requests.length, 3);
487             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
488             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
489             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
490             return MockRemoteAPI.waitForRequest();
491         }).then(() => {
492             assert.equal(requests.length, 6);
493             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
494             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
495                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1})
496             });
497             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
498             return MockRemoteAPI.waitForRequest();
499         }).then(() => {
500             assert.equal(requests.length, 7);
501             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
502             assert.deepEqual(requests[6].data, {'wk': '191622', 'build-request-id': '2', 'forcescheduler': 'force-ab-builds', 'checkbox': 'build-wk', 'build-wk': true});
503             return MockRemoteAPI.waitForRequest();
504         }).then(() => {
505             assert.equal(requests.length, 10);
506             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
507             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
508             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
509             return MockRemoteAPI.waitForRequest();
510         }).then(() => {
511             assert.equal(requests.length, 13);
512             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
513             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
514                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2}),
515                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
516             });
517             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
518             return syncPromise;
519         }).then(() => {
520             return TestGroup.fetchForTask(taskId, true);
521         }).then((testGroups) => {
522             assert.equal(testGroups.length, 1);
523             const testGroup = testGroups[0];
524             const webkit = Repository.findById(MockData.webkitRepositoryId());
525             assert.equal(testGroup.buildRequests().length, 6);
526
527             const buildRequest = testGroup.buildRequests()[0];
528             assert(buildRequest.isBuild());
529             assert(!buildRequest.isTest());
530             assert.equal(buildRequest.statusLabel(), 'Completed');
531             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
532             assert.notEqual(buildRequest.buildId(), null);
533
534             const commitSet = buildRequest.commitSet();
535             assert.equal(commitSet.revisionForRepository(webkit), '191622');
536             const webkitPatch = commitSet.patchForRepository(webkit);
537             assert(webkitPatch instanceof UploadedFile);
538             assert.equal(webkitPatch.filename(), 'patch.dat');
539             const webkitRoot = commitSet.rootForRepository(webkit);
540             assert(webkitRoot instanceof UploadedFile);
541             assert.equal(webkitRoot.filename(), 'root123.dat');
542             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
543
544             const otherBuildRequest = testGroup.buildRequests()[1];
545             assert(otherBuildRequest.isBuild());
546             assert(!otherBuildRequest.isTest());
547             assert.equal(otherBuildRequest.statusLabel(), 'Running');
548             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
549             assert.equal(otherBuildRequest.buildId(), null);
550
551             const otherCommitSet = otherBuildRequest.commitSet();
552             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
553             assert.equal(otherCommitSet.patchForRepository(webkit), null);
554             assert.equal(otherCommitSet.rootForRepository(webkit), null);
555             assert.deepEqual(otherCommitSet.allRootFiles(), []);
556
557             return uploadRoot(otherBuildRequest.id(), 124);
558         }).then(() => {
559             return TestGroup.fetchForTask(taskId, true);
560         }).then((testGroups) => {
561             assert.equal(testGroups.length, 1);
562             const testGroup = testGroups[0];
563             const webkit = Repository.findById(MockData.webkitRepositoryId());
564             assert.equal(testGroup.buildRequests().length, 6);
565
566             const buildRequest = testGroup.buildRequests()[0];
567             assert(buildRequest.isBuild());
568             assert(!buildRequest.isTest());
569             assert.equal(buildRequest.statusLabel(), 'Completed');
570             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
571             assert.notEqual(buildRequest.buildId(), null);
572
573             const commitSet = buildRequest.commitSet();
574             assert.equal(commitSet.revisionForRepository(webkit), '191622');
575             const webkitPatch = commitSet.patchForRepository(webkit);
576             assert(webkitPatch instanceof UploadedFile);
577             assert.equal(webkitPatch.filename(), 'patch.dat');
578             const webkitRoot = commitSet.rootForRepository(webkit);
579             assert(webkitRoot instanceof UploadedFile);
580             assert.equal(webkitRoot.filename(), 'root123.dat');
581             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
582
583             const otherBuildRequest = testGroup.buildRequests()[1];
584             assert(otherBuildRequest.isBuild());
585             assert(!otherBuildRequest.isTest());
586             assert.equal(otherBuildRequest.statusLabel(), 'Completed');
587             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
588             assert.notEqual(otherBuildRequest.buildId(), null);
589
590             const otherCommitSet = otherBuildRequest.commitSet();
591             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
592             assert.equal(otherCommitSet.patchForRepository(webkit), null);
593             const otherWebkitRoot = otherCommitSet.rootForRepository(webkit);
594             assert(otherWebkitRoot instanceof UploadedFile);
595             assert.equal(otherWebkitRoot.filename(), 'root124.dat');
596             assert.deepEqual(otherCommitSet.allRootFiles(), [otherWebkitRoot]);
597         });
598     });
599
600     it('should schedule a build with platform in build property', () => {
601         const requests = MockRemoteAPI.requests;
602         let triggerable;
603         let taskId = null;
604         let syncPromise;
605         return createTriggerable(configWithPlatformName).then((newTriggerable) => {
606             triggerable = newTriggerable;
607             return createTestGroupWihPatch();
608         }).then((testGroup) => {
609             taskId = testGroup.task().id();
610             const webkit = Repository.findById(MockData.webkitRepositoryId());
611             assert.equal(testGroup.buildRequests().length, 6);
612
613             const buildRequest = testGroup.buildRequests()[0];
614             assert(buildRequest.isBuild());
615             assert(!buildRequest.isTest());
616             assert.equal(buildRequest.statusLabel(), 'Waiting');
617             assert.equal(buildRequest.statusUrl(), null);
618             assert.equal(buildRequest.buildId(), null);
619
620             const commitSet = buildRequest.commitSet();
621             assert.equal(commitSet.revisionForRepository(webkit), '191622');
622             const webkitPatch = commitSet.patchForRepository(webkit);
623             assert(webkitPatch instanceof UploadedFile);
624             assert.equal(webkitPatch.filename(), 'patch.dat');
625             assert.equal(commitSet.rootForRepository(webkit), null);
626             assert.deepEqual(commitSet.allRootFiles(), []);
627
628             const otherBuildRequest = testGroup.buildRequests()[1];
629             assert(otherBuildRequest.isBuild());
630             assert(!otherBuildRequest.isTest());
631             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
632             assert.equal(otherBuildRequest.statusUrl(), null);
633             assert.equal(otherBuildRequest.buildId(), null);
634
635             const otherCommitSet = otherBuildRequest.commitSet();
636             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
637             assert.equal(otherCommitSet.patchForRepository(webkit), null);
638             assert.equal(otherCommitSet.rootForRepository(webkit), null);
639             assert.deepEqual(otherCommitSet.allRootFiles(), []);
640
641             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
642             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
643             MockRemoteAPI.reset();
644             return MockRemoteAPI.waitForRequest();
645         }).then(() => {
646             assert.equal(requests.length, 3);
647             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
648             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
649             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
650             return MockRemoteAPI.waitForRequest();
651         }).then(() => {
652             assert.equal(requests.length, 6);
653             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
654             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
655             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
656             return MockRemoteAPI.waitForRequest();
657         }).then(() => {
658             assert.equal(requests.length, 7);
659             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
660             assert.deepEqual(requests[6].data, {'wk': '191622', 'wk-patch': RemoteAPI.url('/api/uploaded-file/1.dat'),
661                 'build-request-id': '1', 'forcescheduler': 'force-ab-builds', 'checkbox': 'build-wk', 'build-wk': true, 'platform-name': 'some platform'});
662             return MockRemoteAPI.waitForRequest();
663         }).then(() => {
664             assert.equal(requests.length, 10);
665             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
666             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds',
667                 [MockData.pendingBuild({builder: 'some builder', buildRequestId: 1})]);
668             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
669             return MockRemoteAPI.waitForRequest();
670         }).then(() => {
671             assert.equal(requests.length, 13);
672             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
673             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
674                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 1})
675             });
676             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
677             return syncPromise;
678         }).then(() => {
679             return TestGroup.fetchForTask(taskId, true);
680         }).then((testGroups) => {
681             assert.equal(testGroups.length, 1);
682             const testGroup = testGroups[0];
683             const webkit = Repository.findById(MockData.webkitRepositoryId());
684             assert.equal(testGroup.buildRequests().length, 6);
685
686             const buildRequest = testGroup.buildRequests()[0];
687             assert(buildRequest.isBuild());
688             assert(!buildRequest.isTest());
689             assert.equal(buildRequest.statusLabel(), 'Running');
690             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
691             assert.equal(buildRequest.buildId(), null);
692
693             const commitSet = buildRequest.commitSet();
694             assert.equal(commitSet.revisionForRepository(webkit), '191622');
695             const webkitPatch = commitSet.patchForRepository(webkit);
696             assert(webkitPatch instanceof UploadedFile);
697             assert.equal(webkitPatch.filename(), 'patch.dat');
698             assert.equal(commitSet.rootForRepository(webkit), null);
699             assert.deepEqual(commitSet.allRootFiles(), []);
700
701             const otherBuildRequest = testGroup.buildRequests()[1];
702             assert(otherBuildRequest.isBuild());
703             assert(!otherBuildRequest.isTest());
704             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
705             assert.equal(otherBuildRequest.statusUrl(), null);
706             assert.equal(otherBuildRequest.buildId(), null);
707
708             const otherCommitSet = otherBuildRequest.commitSet();
709             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
710             assert.equal(otherCommitSet.patchForRepository(webkit), null);
711             assert.equal(otherCommitSet.rootForRepository(webkit), null);
712             assert.deepEqual(otherCommitSet.allRootFiles(), []);
713
714             return uploadRoot(buildRequest.id(), 123);
715         }).then(() => {
716             return TestGroup.fetchForTask(taskId, true);
717         }).then((testGroups) => {
718             assert.equal(testGroups.length, 1);
719             const testGroup = testGroups[0];
720             const webkit = Repository.findById(MockData.webkitRepositoryId());
721             assert.equal(testGroup.buildRequests().length, 6);
722
723             const buildRequest = testGroup.buildRequests()[0];
724             assert(buildRequest.isBuild());
725             assert(!buildRequest.isTest());
726             assert.equal(buildRequest.statusLabel(), 'Completed');
727             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
728             assert.notEqual(buildRequest.buildId(), null);
729
730             const commitSet = buildRequest.commitSet();
731             assert.equal(commitSet.revisionForRepository(webkit), '191622');
732             const webkitPatch = commitSet.patchForRepository(webkit);
733             assert(webkitPatch instanceof UploadedFile);
734             assert.equal(webkitPatch.filename(), 'patch.dat');
735             const webkitRoot = commitSet.rootForRepository(webkit);
736             assert(webkitRoot instanceof UploadedFile);
737             assert.equal(webkitRoot.filename(), 'root123.dat');
738             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
739
740             const otherBuildRequest = testGroup.buildRequests()[1];
741             assert(otherBuildRequest.isBuild());
742             assert(!otherBuildRequest.isTest());
743             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
744             assert.equal(otherBuildRequest.statusUrl(), null);
745             assert.equal(otherBuildRequest.buildId(), null);
746
747             const otherCommitSet = otherBuildRequest.commitSet();
748             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
749             assert.equal(otherCommitSet.patchForRepository(webkit), null);
750             assert.equal(otherCommitSet.rootForRepository(webkit), null);
751             assert.deepEqual(otherCommitSet.allRootFiles(), []);
752
753             MockRemoteAPI.reset();
754             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
755             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
756             MockRemoteAPI.reset();
757             return MockRemoteAPI.waitForRequest();
758         }).then(() => {
759             assert.equal(requests.length, 3);
760             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
761             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
762             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
763             return MockRemoteAPI.waitForRequest();
764         }).then(() => {
765             assert.equal(requests.length, 6);
766             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
767             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
768                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1})
769             });
770             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
771             return MockRemoteAPI.waitForRequest();
772         }).then(() => {
773             assert.equal(requests.length, 7);
774             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
775             assert.deepEqual(requests[6].data, {'wk': '191622', 'build-request-id': '2', 'forcescheduler': 'force-ab-builds', 'checkbox': 'build-wk', 'build-wk': true, 'platform-name': 'some platform'});
776             return MockRemoteAPI.waitForRequest();
777         }).then(() => {
778             assert.equal(requests.length, 10);
779             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
780             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
781             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
782             return MockRemoteAPI.waitForRequest();
783         }).then(() => {
784             assert.equal(requests.length, 13);
785             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
786             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
787                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2}),
788                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
789             });
790             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
791             return syncPromise;
792         }).then(() => {
793             return TestGroup.fetchForTask(taskId, true);
794         }).then((testGroups) => {
795             assert.equal(testGroups.length, 1);
796             const testGroup = testGroups[0];
797             const webkit = Repository.findById(MockData.webkitRepositoryId());
798             assert.equal(testGroup.buildRequests().length, 6);
799
800             const buildRequest = testGroup.buildRequests()[0];
801             assert(buildRequest.isBuild());
802             assert(!buildRequest.isTest());
803             assert.equal(buildRequest.statusLabel(), 'Completed');
804             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
805             assert.notEqual(buildRequest.buildId(), null);
806
807             const commitSet = buildRequest.commitSet();
808             assert.equal(commitSet.revisionForRepository(webkit), '191622');
809             const webkitPatch = commitSet.patchForRepository(webkit);
810             assert(webkitPatch instanceof UploadedFile);
811             assert.equal(webkitPatch.filename(), 'patch.dat');
812             const webkitRoot = commitSet.rootForRepository(webkit);
813             assert(webkitRoot instanceof UploadedFile);
814             assert.equal(webkitRoot.filename(), 'root123.dat');
815             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
816
817             const otherBuildRequest = testGroup.buildRequests()[1];
818             assert(otherBuildRequest.isBuild());
819             assert(!otherBuildRequest.isTest());
820             assert.equal(otherBuildRequest.statusLabel(), 'Running');
821             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
822             assert.equal(otherBuildRequest.buildId(), null);
823
824             const otherCommitSet = otherBuildRequest.commitSet();
825             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
826             assert.equal(otherCommitSet.patchForRepository(webkit), null);
827             assert.equal(otherCommitSet.rootForRepository(webkit), null);
828             assert.deepEqual(otherCommitSet.allRootFiles(), []);
829
830             return uploadRoot(otherBuildRequest.id(), 124);
831         }).then(() => {
832             return TestGroup.fetchForTask(taskId, true);
833         }).then((testGroups) => {
834             assert.equal(testGroups.length, 1);
835             const testGroup = testGroups[0];
836             const webkit = Repository.findById(MockData.webkitRepositoryId());
837             assert.equal(testGroup.buildRequests().length, 6);
838
839             const buildRequest = testGroup.buildRequests()[0];
840             assert(buildRequest.isBuild());
841             assert(!buildRequest.isTest());
842             assert.equal(buildRequest.statusLabel(), 'Completed');
843             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
844             assert.notEqual(buildRequest.buildId(), null);
845
846             const commitSet = buildRequest.commitSet();
847             assert.equal(commitSet.revisionForRepository(webkit), '191622');
848             const webkitPatch = commitSet.patchForRepository(webkit);
849             assert(webkitPatch instanceof UploadedFile);
850             assert.equal(webkitPatch.filename(), 'patch.dat');
851             const webkitRoot = commitSet.rootForRepository(webkit);
852             assert(webkitRoot instanceof UploadedFile);
853             assert.equal(webkitRoot.filename(), 'root123.dat');
854             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
855
856             const otherBuildRequest = testGroup.buildRequests()[1];
857             assert(otherBuildRequest.isBuild());
858             assert(!otherBuildRequest.isTest());
859             assert.equal(otherBuildRequest.statusLabel(), 'Completed');
860             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
861             assert.notEqual(otherBuildRequest.buildId(), null);
862
863             const otherCommitSet = otherBuildRequest.commitSet();
864             assert.equal(otherCommitSet.revisionForRepository(webkit), '191622');
865             assert.equal(otherCommitSet.patchForRepository(webkit), null);
866             const otherWebkitRoot = otherCommitSet.rootForRepository(webkit);
867             assert(otherWebkitRoot instanceof UploadedFile);
868             assert.equal(otherWebkitRoot.filename(), 'root124.dat');
869             assert.deepEqual(otherCommitSet.allRootFiles(), [otherWebkitRoot]);
870         });
871     });
872
873     it('should schedule a build to test after building a patch', () => {
874         const requests = MockRemoteAPI.requests;
875         let triggerable;
876         let taskId = null;
877         let syncPromise;
878         let firstRoot = null;
879         return createTriggerable().then((newTriggerable) => {
880             triggerable = newTriggerable;
881             return createTestGroupWihPatch();
882         }).then((testGroup) => {
883             taskId = testGroup.task().id();
884             const webkit = Repository.findById(MockData.webkitRepositoryId());
885             assert.equal(testGroup.buildRequests().length, 6);
886
887             const buildRequest = testGroup.buildRequests()[0];
888             assert.equal(buildRequest.id(), 1);
889             assert(buildRequest.isBuild());
890             assert(!buildRequest.isTest());
891             assert.equal(buildRequest.statusLabel(), 'Waiting');
892             assert.equal(buildRequest.buildId(), null);
893             assert.deepEqual(buildRequest.commitSet().allRootFiles(), []);
894
895             const otherBuildRequest = testGroup.buildRequests()[1];
896             assert.equal(otherBuildRequest.id(), 2);
897             assert(otherBuildRequest.isBuild());
898             assert(!otherBuildRequest.isTest());
899             assert.equal(buildRequest.statusLabel(), 'Waiting');
900             assert.equal(otherBuildRequest.buildId(), null);
901             assert.deepEqual(otherBuildRequest.commitSet().allRootFiles(), []);
902
903             return uploadRoot(1, 45);
904         }).then(() => {
905             return uploadRoot(2, 46);
906         }).then(() => {
907             return TestGroup.fetchForTask(taskId, true);
908         }).then((testGroups) => {
909             assert.equal(testGroups.length, 1);
910             const testGroup = testGroups[0];
911
912             const buildRequest = testGroup.buildRequests()[0];
913             assert(buildRequest.isBuild());
914             assert(!buildRequest.isTest());
915             assert.equal(buildRequest.statusLabel(), 'Completed');
916             assert.notEqual(buildRequest.buildId(), null);
917             const roots = buildRequest.commitSet().allRootFiles();
918             assert.equal(roots.length, 1);
919             firstRoot = roots[0];
920             assert.deepEqual(roots[0].filename(), 'root45.dat');
921
922             const otherBuildRequest = testGroup.buildRequests()[1];
923             assert(otherBuildRequest.isBuild());
924             assert(!otherBuildRequest.isTest());
925             assert.equal(otherBuildRequest.statusLabel(), 'Completed');
926             assert.notEqual(otherBuildRequest.buildId(), null);
927             const otherRoots = otherBuildRequest.commitSet().allRootFiles();
928             assert.equal(otherRoots.length, 1);
929             assert.deepEqual(otherRoots[0].filename(), 'root46.dat');
930             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
931             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
932             MockRemoteAPI.reset();
933             return MockRemoteAPI.waitForRequest();
934         }).then(() => {
935             assert.equal(requests.length, 3);
936             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
937             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
938             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
939             return MockRemoteAPI.waitForRequest();
940         }).then(() => {
941             assert.equal(requests.length, 6);
942             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
943             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
944                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
945                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 2}),
946             });
947             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
948             return MockRemoteAPI.waitForRequest();
949         }).then(() => {
950             assert.equal(requests.length, 7);
951             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20tester/force', 'OK');
952             assert.deepEqual(requests[6].data, {'test': 'some-test', 'wk': '191622', 'build-request-id': '3', 'forcescheduler': 'force-ab-tests',
953                 'roots': JSON.stringify([{url: firstRoot.url()}])});
954             return MockRemoteAPI.waitForRequest();
955         }).then(() => {
956             assert.equal(requests.length, 10);
957             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', [
958                 MockData.pendingBuild({builder: 'some tester', buildRequestId: 3}),
959             ]);
960             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
961             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
962             return MockRemoteAPI.waitForRequest();
963         }).then(() => {
964             assert.equal(requests.length, 13);
965             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
966             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
967                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
968                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 2}),
969             });
970             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
971             return syncPromise;
972         });
973     });
974
975     it('should not schedule a build to test while building a patch', () => {
976         const requests = MockRemoteAPI.requests;
977         let triggerable;
978         let taskId = null;
979         let syncPromise;
980         return createTriggerable().then((newTriggerable) => {
981             triggerable = newTriggerable;
982             return createTestGroupWihPatch();
983         }).then((testGroup) => {
984             taskId = testGroup.task().id();
985             assert.equal(testGroup.buildRequests().length, 6);
986
987             const buildRequest = testGroup.buildRequests()[0];
988             assert.equal(buildRequest.id(), 1);
989             assert(buildRequest.isBuild());
990             assert(!buildRequest.isTest());
991             assert.equal(buildRequest.statusLabel(), 'Waiting');
992             assert.equal(buildRequest.statusUrl(), null);
993             assert.equal(buildRequest.buildId(), null);
994
995             const otherBuildRequest = testGroup.buildRequests()[1];
996             assert.equal(otherBuildRequest.id(), 2);
997             assert(otherBuildRequest.isBuild());
998             assert(!otherBuildRequest.isTest());
999             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1000             assert.equal(otherBuildRequest.statusUrl(), null);
1001             assert.equal(otherBuildRequest.buildId(), null);
1002
1003             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1004             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1005             MockRemoteAPI.reset();
1006             return Promise.all([MockRemoteAPI.waitForRequest(), uploadRoot(1, 123)]);
1007         }).then(() => {
1008             assert.equal(requests.length, 3);
1009             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1010             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1011             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1012             return MockRemoteAPI.waitForRequest();
1013         }).then(() => {
1014             assert.equal(requests.length, 6);
1015             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1016             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1017                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2}),
1018                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
1019             });
1020             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1021             return MockRemoteAPI.waitForRequest();
1022         }).then(() => {
1023             assert.equal(requests.length, 9);
1024             assertAndResolveRequest(requests[6], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1025             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1026             assertAndResolveRequest(requests[8], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1027             return MockRemoteAPI.waitForRequest();
1028         }).then(() => {
1029             assert.equal(requests.length, 12);
1030             assertAndResolveRequest(requests[9], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1031             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1032                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2, buildNumber: 1002}),
1033                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
1034             });
1035             assertAndResolveRequest(requests[11], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1036             return syncPromise;
1037         }).then(() => {
1038             return TestGroup.fetchForTask(taskId, true);
1039         }).then((testGroups) => {
1040             assert.equal(testGroups.length, 1);
1041
1042             const testGroup = testGroups[0];
1043             const buildRequest = testGroup.buildRequests()[0];
1044             assert.equal(buildRequest.id(), 1);
1045             assert(buildRequest.isBuild());
1046             assert(!buildRequest.isTest());
1047             assert.equal(buildRequest.statusLabel(), 'Completed');
1048             assert.equal(buildRequest.statusUrl(), null);
1049             assert.notEqual(buildRequest.buildId(), null);
1050
1051             const otherBuildRequest = testGroup.buildRequests()[1];
1052             assert.equal(otherBuildRequest.id(), 2);
1053             assert(otherBuildRequest.isBuild());
1054             assert(!otherBuildRequest.isTest());
1055             assert.equal(otherBuildRequest.statusLabel(), 'Running');
1056             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/1002');
1057             assert.equal(otherBuildRequest.buildId(), null);
1058         });
1059     });
1060
1061     it('should cancel builds for testing when a build to build a patch fails', () => {
1062         const requests = MockRemoteAPI.requests;
1063         let triggerable;
1064         let taskId = null;
1065         let syncPromise;
1066         return createTriggerable().then((newTriggerable) => {
1067             triggerable = newTriggerable;
1068             return createTestGroupWihPatch();
1069         }).then((testGroup) => {
1070             taskId = testGroup.task().id();
1071             assert.equal(testGroup.buildRequests().length, 6);
1072
1073             const buildRequest = testGroup.buildRequests()[0];
1074             assert.equal(buildRequest.id(), 1);
1075             assert(buildRequest.isBuild());
1076             assert(!buildRequest.isTest());
1077             assert.equal(buildRequest.statusLabel(), 'Waiting');
1078             assert.equal(buildRequest.statusUrl(), null);
1079             assert.equal(buildRequest.buildId(), null);
1080
1081             const otherBuildRequest = testGroup.buildRequests()[1];
1082             assert.equal(otherBuildRequest.id(), 2);
1083             assert(otherBuildRequest.isBuild());
1084             assert(!otherBuildRequest.isTest());
1085             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1086             assert.equal(otherBuildRequest.statusUrl(), null);
1087             assert.equal(otherBuildRequest.buildId(), null);
1088
1089             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1090             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1091             MockRemoteAPI.reset();
1092             return MockRemoteAPI.waitForRequest();
1093         }).then(() => {
1094             assert.equal(requests.length, 3);
1095             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1096             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1097             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1098             return MockRemoteAPI.waitForRequest();
1099         }).then(() => {
1100             assert.equal(requests.length, 6);
1101             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1102             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
1103             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {
1104                 [-1]: MockData.finishedBuild({builder: 'other builder', buildRequestId: 1, buildNumber: 312}),
1105             });
1106             return MockRemoteAPI.waitForRequest();
1107         }).then(() => {
1108             assert.equal(requests.length, 9);
1109             assertAndResolveRequest(requests[6], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1110             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1111             assertAndResolveRequest(requests[8], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1112             return MockRemoteAPI.waitForRequest();
1113         }).then(() => {
1114             assert.equal(requests.length, 12);
1115             assertAndResolveRequest(requests[9], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1116             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
1117             assertAndResolveRequest(requests[11], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {
1118                 [-1]: MockData.finishedBuild({builder: 'other builder', buildRequestId: 1, buildNumber: 312}),
1119             });
1120             return syncPromise;
1121         }).then(() => {
1122             return TestGroup.fetchForTask(taskId, true);
1123         }).then((testGroups) => {
1124             assert.equal(testGroups.length, 1);
1125
1126             const buildReqeusts = testGroups[0].buildRequests();
1127             assert(buildReqeusts[0].isBuild());
1128             assert(!buildReqeusts[0].isTest());
1129             assert.equal(buildReqeusts[0].statusLabel(), 'Failed');
1130             assert.equal(buildReqeusts[0].statusUrl(), 'http://build.webkit.org/builders/other%20builder/builds/312');
1131             assert.equal(buildReqeusts[0].buildId(), null);
1132
1133             assert(buildReqeusts[1].isBuild());
1134             assert(!buildReqeusts[1].isTest());
1135             assert.equal(buildReqeusts[1].statusLabel(), 'Failed');
1136             assert.equal(buildReqeusts[1].statusUrl(), null);
1137             assert.equal(buildReqeusts[1].buildId(), null);
1138
1139             function assertTestBuildHasFailed(request)
1140             {
1141                 assert(!request.isBuild());
1142                 assert(request.isTest());
1143                 assert.equal(request.statusLabel(), 'Failed');
1144                 assert.equal(request.statusUrl(), null);
1145                 assert.equal(request.buildId(), null);
1146             }
1147
1148             assertTestBuildHasFailed(buildReqeusts[2]);
1149             assertTestBuildHasFailed(buildReqeusts[3]);
1150         });
1151     });
1152
1153     it('should schedule a build to build binary for owned commits', () => {
1154         const requests = MockRemoteAPI.requests;
1155         let triggerable;
1156         let taskId = null;
1157         let syncPromise;
1158         return createTriggerable().then((newTriggerable) => {
1159             triggerable = newTriggerable;
1160             return createTestGroupWihOwnedCommit();
1161         }).then((testGroup) => {
1162             taskId = testGroup.task().id();
1163             const webkit = Repository.findById(MockData.webkitRepositoryId());
1164             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1165             assert.equal(testGroup.buildRequests().length, 6);
1166
1167             const buildRequest = testGroup.buildRequests()[0];
1168             assert(buildRequest.isBuild());
1169             assert(!buildRequest.isTest());
1170             assert.equal(buildRequest.statusLabel(), 'Waiting');
1171             assert.equal(buildRequest.statusUrl(), null);
1172             assert.equal(buildRequest.buildId(), null);
1173
1174             const commitSet = buildRequest.commitSet();
1175             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1176             assert.equal(commitSet.patchForRepository(webkit), null);
1177             assert.equal(commitSet.rootForRepository(webkit), null);
1178             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1179             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1180             assert.deepEqual(commitSet.allRootFiles(), []);
1181
1182             const otherBuildRequest = testGroup.buildRequests()[1];
1183             assert(otherBuildRequest.isBuild());
1184             assert(!otherBuildRequest.isTest());
1185             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1186             assert.equal(otherBuildRequest.statusUrl(), null);
1187             assert.equal(otherBuildRequest.buildId(), null);
1188
1189             const otherCommitSet = otherBuildRequest.commitSet();
1190             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1191             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1192             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1193             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1194             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1195             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1196
1197             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1198             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1199             MockRemoteAPI.reset();
1200             return MockRemoteAPI.waitForRequest();
1201         }).then(() => {
1202             assert.equal(requests.length, 3);
1203             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1204             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1205             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1206             return MockRemoteAPI.waitForRequest();
1207         }).then(() => {
1208             assert.equal(requests.length, 6);
1209             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1210             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
1211             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1212             return MockRemoteAPI.waitForRequest();
1213         }).then(() => {
1214             assert.equal(requests.length, 7);
1215             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
1216             assert.deepEqual(requests[6].data, {'wk': '191622', 'build-request-id': '1', 'forcescheduler': 'force-ab-builds', 'owned-commits': `{"WebKit":[{"revision":"owned-jsc-6161","repository":"JavaScriptCore","ownerRevision":"191622"}]}`});
1217             return MockRemoteAPI.waitForRequest();
1218         }).then(() => {
1219             assert.equal(requests.length, 10);
1220             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1221             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds',
1222                 [MockData.pendingBuild({builder: 'some builder', buildRequestId: 1})]);
1223             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1224             return MockRemoteAPI.waitForRequest();
1225         }).then(() => {
1226             assert.equal(requests.length, 13);
1227             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1228             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1229                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 1})
1230             });
1231             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1232             return syncPromise;
1233         }).then(() => {
1234             return TestGroup.fetchForTask(taskId, true);
1235         }).then((testGroups) => {
1236             assert.equal(testGroups.length, 1);
1237             const testGroup = testGroups[0];
1238             const webkit = Repository.findById(MockData.webkitRepositoryId());
1239             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1240             assert.equal(testGroup.buildRequests().length, 6);
1241
1242             const buildRequest = testGroup.buildRequests()[0];
1243             assert(buildRequest.isBuild());
1244             assert(!buildRequest.isTest());
1245             assert.equal(buildRequest.statusLabel(), 'Running');
1246             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1247             assert.equal(buildRequest.buildId(), null);
1248
1249             const commitSet = buildRequest.commitSet();
1250             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1251             assert.equal(commitSet.patchForRepository(webkit), null);
1252             assert.equal(commitSet.rootForRepository(webkit), null);
1253             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1254             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1255             assert.deepEqual(commitSet.allRootFiles(), []);
1256
1257             const otherBuildRequest = testGroup.buildRequests()[1];
1258             assert(otherBuildRequest.isBuild());
1259             assert(!otherBuildRequest.isTest());
1260             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1261             assert.equal(otherBuildRequest.statusUrl(), null);
1262             assert.equal(otherBuildRequest.buildId(), null);
1263
1264             const otherCommitSet = otherBuildRequest.commitSet();
1265             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1266             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1267             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1268             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1269             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1270             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1271
1272             return uploadRoot(buildRequest.id(), 123).then(() => uploadRoot(buildRequest.id(), 123, [{ownerRepository: 'WebKit', ownedRepository: 'JavaScriptCore'}], '2017-05-10T02:54:09.666'));
1273         }).then(() => {
1274             return TestGroup.fetchForTask(taskId, true);
1275         }).then((testGroups) => {
1276             assert.equal(testGroups.length, 1);
1277             const testGroup = testGroups[0];
1278             const webkit = Repository.findById(MockData.webkitRepositoryId());
1279             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1280             assert.equal(testGroup.buildRequests().length, 6);
1281
1282             const buildRequest = testGroup.buildRequests()[0];
1283             assert(buildRequest.isBuild());
1284             assert(!buildRequest.isTest());
1285             assert.equal(buildRequest.statusLabel(), 'Completed');
1286             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1287             assert.notEqual(buildRequest.buildId(), null);
1288
1289             const commitSet = buildRequest.commitSet();
1290             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1291             assert.equal(commitSet.patchForRepository(webkit), null);
1292             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1293             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1294             const webkitRoot = commitSet.rootForRepository(webkit);
1295             assert(webkitRoot instanceof UploadedFile);
1296             assert.equal(webkitRoot.filename(), 'root123.dat');
1297             const jscRoot = commitSet.rootForRepository(ownedJSC);
1298             assert(jscRoot instanceof UploadedFile);
1299             assert.equal(jscRoot.filename(), 'root123.dat');
1300             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1301
1302             const otherBuildRequest = testGroup.buildRequests()[1];
1303             assert(otherBuildRequest.isBuild());
1304             assert(!otherBuildRequest.isTest());
1305             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1306             assert.equal(otherBuildRequest.statusUrl(), null);
1307             assert.equal(otherBuildRequest.buildId(), null);
1308
1309             const otherCommitSet = otherBuildRequest.commitSet();
1310             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1311             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1312             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1313             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1314             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1315             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1316
1317             MockRemoteAPI.reset();
1318             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1319             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1320             MockRemoteAPI.reset();
1321             return MockRemoteAPI.waitForRequest();
1322         }).then(() => {
1323             assert.equal(requests.length, 3);
1324             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1325             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1326             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1327             return MockRemoteAPI.waitForRequest();
1328         }).then(() => {
1329             assert.equal(requests.length, 6);
1330             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1331             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1332                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1})
1333             });
1334             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1335             return MockRemoteAPI.waitForRequest();
1336         }).then(() => {
1337             assert.equal(requests.length, 7);
1338             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
1339             assert.deepEqual(requests[6].data, {'wk': '192736', 'build-request-id': '2', 'forcescheduler': 'force-ab-builds', 'owned-commits': `{"WebKit":[{"revision":"owned-jsc-9191","repository":"JavaScriptCore","ownerRevision":"192736"}]}`});
1340             return MockRemoteAPI.waitForRequest();
1341         }).then(() => {
1342             assert.equal(requests.length, 10);
1343             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1344             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1345             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1346             return MockRemoteAPI.waitForRequest();
1347         }).then(() => {
1348             assert.equal(requests.length, 13);
1349             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1350             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1351                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2}),
1352                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
1353             });
1354             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1355             return syncPromise;
1356         }).then(() => {
1357             return TestGroup.fetchForTask(taskId, true);
1358         }).then((testGroups) => {
1359             assert.equal(testGroups.length, 1);
1360             const testGroup = testGroups[0];
1361             const webkit = Repository.findById(MockData.webkitRepositoryId());
1362             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1363             assert.equal(testGroup.buildRequests().length, 6);
1364
1365             const buildRequest = testGroup.buildRequests()[0];
1366             assert(buildRequest.isBuild());
1367             assert(!buildRequest.isTest());
1368             assert.equal(buildRequest.statusLabel(), 'Completed');
1369             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1370             assert.notEqual(buildRequest.buildId(), null);
1371
1372             const commitSet = buildRequest.commitSet();
1373             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1374             assert.equal(commitSet.patchForRepository(webkit), null);
1375             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1376             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1377             const webkitRoot = commitSet.rootForRepository(webkit);
1378             assert(webkitRoot instanceof UploadedFile);
1379             assert.equal(webkitRoot.filename(), 'root123.dat');
1380             const jscRoot = commitSet.rootForRepository(ownedJSC);
1381             assert(jscRoot instanceof UploadedFile);
1382             assert.equal(jscRoot.filename(), 'root123.dat');
1383             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1384
1385             const otherBuildRequest = testGroup.buildRequests()[1];
1386             assert(otherBuildRequest.isBuild());
1387             assert(!otherBuildRequest.isTest());
1388             assert.equal(otherBuildRequest.statusLabel(), 'Running');
1389             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1390             assert.equal(otherBuildRequest.buildId(), null);
1391
1392             const otherCommitSet = otherBuildRequest.commitSet();
1393             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1394             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1395             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1396             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1397             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1398             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1399
1400             return uploadRoot(otherBuildRequest.id(), 124).then(() => uploadRoot(otherBuildRequest.id(), 124, [{ownerRepository: 'WebKit', ownedRepository: 'JavaScriptCore'}], '2017-05-10T02:54:09.666'));
1401         }).then(() => {
1402             return TestGroup.fetchForTask(taskId, true);
1403         }).then((testGroups) => {
1404             assert.equal(testGroups.length, 1);
1405             const testGroup = testGroups[0];
1406             const webkit = Repository.findById(MockData.webkitRepositoryId());
1407             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1408             assert.equal(testGroup.buildRequests().length, 6);
1409
1410             const buildRequest = testGroup.buildRequests()[0];
1411             assert(buildRequest.isBuild());
1412             assert(!buildRequest.isTest());
1413             assert.equal(buildRequest.statusLabel(), 'Completed');
1414             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1415             assert.notEqual(buildRequest.buildId(), null);
1416
1417             const commitSet = buildRequest.commitSet();
1418             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1419             assert.equal(commitSet.patchForRepository(webkit), null);
1420             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1421             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1422             const webkitRoot = commitSet.rootForRepository(webkit);
1423             assert(webkitRoot instanceof UploadedFile);
1424             assert.equal(webkitRoot.filename(), 'root123.dat');
1425             const jscRoot = commitSet.rootForRepository(ownedJSC);
1426             assert(jscRoot instanceof UploadedFile);
1427             assert.equal(jscRoot.filename(), 'root123.dat');
1428             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1429
1430             const otherBuildRequest = testGroup.buildRequests()[1];
1431             assert(otherBuildRequest.isBuild());
1432             assert(!otherBuildRequest.isTest());
1433             assert.equal(otherBuildRequest.statusLabel(), 'Completed');
1434             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1435             assert.notEqual(otherBuildRequest.buildId(), null);
1436
1437             const otherCommitSet = otherBuildRequest.commitSet();
1438             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1439             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1440             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1441             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1442             const otherWebkitRoot = otherCommitSet.rootForRepository(webkit);
1443             assert(otherWebkitRoot instanceof UploadedFile);
1444             assert.equal(otherWebkitRoot.filename(), 'root124.dat');
1445             const otherJSCRoot = otherCommitSet.rootForRepository(ownedJSC);
1446             assert(otherJSCRoot instanceof UploadedFile);
1447             assert.equal(otherJSCRoot.filename(), 'root124.dat');
1448             assert.deepEqual(otherCommitSet.allRootFiles(), [otherWebkitRoot, otherJSCRoot]);
1449         });
1450     });
1451
1452     it('should not update a build request to "completed" until all roots needed in the commit set are uploaded', () => {
1453         const requests = MockRemoteAPI.requests;
1454         let triggerable;
1455         let taskId = null;
1456         let syncPromise;
1457         return createTriggerable().then((newTriggerable) => {
1458             triggerable = newTriggerable;
1459             return createTestGroupWihOwnedCommit();
1460         }).then((testGroup) => {
1461             taskId = testGroup.task().id();
1462             const webkit = Repository.findById(MockData.webkitRepositoryId());
1463             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1464             assert.equal(testGroup.buildRequests().length, 6);
1465
1466             const buildRequest = testGroup.buildRequests()[0];
1467             assert(buildRequest.isBuild());
1468             assert(!buildRequest.isTest());
1469             assert.equal(buildRequest.statusLabel(), 'Waiting');
1470             assert.equal(buildRequest.statusUrl(), null);
1471             assert.equal(buildRequest.buildId(), null);
1472
1473             const commitSet = buildRequest.commitSet();
1474             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1475             assert.equal(commitSet.patchForRepository(webkit), null);
1476             assert.equal(commitSet.rootForRepository(webkit), null);
1477             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1478             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1479             assert.deepEqual(commitSet.allRootFiles(), []);
1480
1481             const otherBuildRequest = testGroup.buildRequests()[1];
1482             assert(otherBuildRequest.isBuild());
1483             assert(!otherBuildRequest.isTest());
1484             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1485             assert.equal(otherBuildRequest.statusUrl(), null);
1486             assert.equal(otherBuildRequest.buildId(), null);
1487
1488             const otherCommitSet = otherBuildRequest.commitSet();
1489             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1490             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1491             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1492             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1493             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1494             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1495
1496             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1497             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1498             MockRemoteAPI.reset();
1499             return MockRemoteAPI.waitForRequest();
1500         }).then(() => {
1501             assert.equal(requests.length, 3);
1502             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1503             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1504             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1505             return MockRemoteAPI.waitForRequest();
1506         }).then(() => {
1507             assert.equal(requests.length, 6);
1508             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1509             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {});
1510             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1511             return MockRemoteAPI.waitForRequest();
1512         }).then(() => {
1513             assert.equal(requests.length, 7);
1514             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
1515             assert.deepEqual(requests[6].data, {'wk': '191622', 'build-request-id': '1', 'forcescheduler': 'force-ab-builds', 'owned-commits': `{"WebKit":[{"revision":"owned-jsc-6161","repository":"JavaScriptCore","ownerRevision":"191622"}]}`});
1516             return MockRemoteAPI.waitForRequest();
1517         }).then(() => {
1518             assert.equal(requests.length, 10);
1519             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1520             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds',
1521                 [MockData.pendingBuild({builder: 'some builder', buildRequestId: 1})]);
1522             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1523             return MockRemoteAPI.waitForRequest();
1524         }).then(() => {
1525             assert.equal(requests.length, 13);
1526             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1527             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1528                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 1})
1529             });
1530             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1531             return syncPromise;
1532         }).then(() => {
1533             return TestGroup.fetchForTask(taskId, true);
1534         }).then((testGroups) => {
1535             assert.equal(testGroups.length, 1);
1536             const testGroup = testGroups[0];
1537             const webkit = Repository.findById(MockData.webkitRepositoryId());
1538             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1539             assert.equal(testGroup.buildRequests().length, 6);
1540
1541             const buildRequest = testGroup.buildRequests()[0];
1542             assert(buildRequest.isBuild());
1543             assert(!buildRequest.isTest());
1544             assert.equal(buildRequest.statusLabel(), 'Running');
1545             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1546             assert.equal(buildRequest.buildId(), null);
1547
1548             const commitSet = buildRequest.commitSet();
1549             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1550             assert.equal(commitSet.patchForRepository(webkit), null);
1551             assert.equal(commitSet.rootForRepository(webkit), null);
1552             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1553             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1554             assert.deepEqual(commitSet.allRootFiles(), []);
1555
1556             const otherBuildRequest = testGroup.buildRequests()[1];
1557             assert(otherBuildRequest.isBuild());
1558             assert(!otherBuildRequest.isTest());
1559             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1560             assert.equal(otherBuildRequest.statusUrl(), null);
1561             assert.equal(otherBuildRequest.buildId(), null);
1562
1563             const otherCommitSet = otherBuildRequest.commitSet();
1564             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1565             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1566             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1567             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1568             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1569             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1570
1571             return uploadRoot(buildRequest.id(), 123);
1572         }).then(() => {
1573             return TestGroup.fetchForTask(taskId, true);
1574         }).then((testGroups) => {
1575             assert.equal(testGroups.length, 1);
1576             const testGroup = testGroups[0];
1577             const webkit = Repository.findById(MockData.webkitRepositoryId());
1578             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1579             assert.equal(testGroup.buildRequests().length, 6);
1580
1581             const buildRequest = testGroup.buildRequests()[0];
1582             assert(buildRequest.isBuild());
1583             assert(!buildRequest.isTest());
1584             assert.equal(buildRequest.statusLabel(), 'Running');
1585             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1586             assert.equal(buildRequest.buildId(), null);
1587
1588             const commitSet = buildRequest.commitSet();
1589             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1590             assert.equal(commitSet.patchForRepository(webkit), null);
1591             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1592             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1593             const webkitRoot = commitSet.rootForRepository(webkit);
1594             assert(webkitRoot instanceof UploadedFile);
1595             assert.equal(webkitRoot.filename(), 'root123.dat');
1596             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot]);
1597
1598             const otherBuildRequest = testGroup.buildRequests()[1];
1599             assert(otherBuildRequest.isBuild());
1600             assert(!otherBuildRequest.isTest());
1601             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1602             assert.equal(otherBuildRequest.statusUrl(), null);
1603             assert.equal(otherBuildRequest.buildId(), null);
1604
1605             const otherCommitSet = otherBuildRequest.commitSet();
1606             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1607             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1608             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1609             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1610             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1611             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1612             return uploadRoot(buildRequest.id(), 123, [{ownerRepository: 'WebKit', ownedRepository: 'JavaScriptCore'}], '2017-05-10T02:54:09.666');
1613         }).then(() => {
1614             return TestGroup.fetchForTask(taskId, true);
1615         }).then((testGroups) => {
1616             assert.equal(testGroups.length, 1);
1617             const testGroup = testGroups[0];
1618             const webkit = Repository.findById(MockData.webkitRepositoryId());
1619             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1620             assert.equal(testGroup.buildRequests().length, 6);
1621
1622             const buildRequest = testGroup.buildRequests()[0];
1623             assert(buildRequest.isBuild());
1624             assert(!buildRequest.isTest());
1625             assert.equal(buildRequest.statusLabel(), 'Completed');
1626             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1627             assert.notEqual(buildRequest.buildId(), null);
1628
1629             const commitSet = buildRequest.commitSet();
1630             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1631             assert.equal(commitSet.patchForRepository(webkit), null);
1632             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1633             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1634             const webkitRoot = commitSet.rootForRepository(webkit);
1635             assert(webkitRoot instanceof UploadedFile);
1636             assert.equal(webkitRoot.filename(), 'root123.dat');
1637             const jscRoot = commitSet.rootForRepository((ownedJSC));
1638             assert(jscRoot instanceof UploadedFile);
1639             assert.equal(jscRoot.filename(), 'root123.dat');
1640             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1641
1642             const otherBuildRequest = testGroup.buildRequests()[1];
1643             assert(otherBuildRequest.isBuild());
1644             assert(!otherBuildRequest.isTest());
1645             assert.equal(otherBuildRequest.statusLabel(), 'Waiting');
1646             assert.equal(otherBuildRequest.statusUrl(), null);
1647             assert.equal(otherBuildRequest.buildId(), null);
1648
1649             const otherCommitSet = otherBuildRequest.commitSet();
1650             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1651             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1652             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1653             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1654             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1655             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1656
1657             MockRemoteAPI.reset();
1658             syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
1659             assertAndResolveRequest(requests[0], 'GET', MockData.buildbotBuildersURLDeprecated(), MockData.mockBuildbotBuildersDeprecated());
1660             MockRemoteAPI.reset();
1661             return MockRemoteAPI.waitForRequest();
1662         }).then(() => {
1663             assert.equal(requests.length, 3);
1664             assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1665             assertAndResolveRequest(requests[1], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1666             assertAndResolveRequest(requests[2], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1667             return MockRemoteAPI.waitForRequest();
1668         }).then(() => {
1669             assert.equal(requests.length, 6);
1670             assertAndResolveRequest(requests[3], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1671             assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1672                 [-1]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1})
1673             });
1674             assertAndResolveRequest(requests[5], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1675             return MockRemoteAPI.waitForRequest();
1676         }).then(() => {
1677             assert.equal(requests.length, 7);
1678             assertAndResolveRequest(requests[6], 'POST', '/builders/some%20builder/force', 'OK');
1679             assert.deepEqual(requests[6].data, {'wk': '192736', 'build-request-id': '2', 'forcescheduler': 'force-ab-builds', 'owned-commits': `{"WebKit":[{"revision":"owned-jsc-9191","repository":"JavaScriptCore","ownerRevision":"192736"}]}`});
1680             return MockRemoteAPI.waitForRequest();
1681         }).then(() => {
1682             assert.equal(requests.length, 10);
1683             assertAndResolveRequest(requests[7], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
1684             assertAndResolveRequest(requests[8], 'GET', '/json/builders/some%20builder/pendingBuilds', []);
1685             assertAndResolveRequest(requests[9], 'GET', '/json/builders/other%20builder/pendingBuilds', []);
1686             return MockRemoteAPI.waitForRequest();
1687         }).then(() => {
1688             assert.equal(requests.length, 13);
1689             assertAndResolveRequest(requests[10], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {});
1690             assertAndResolveRequest(requests[11], 'GET', '/json/builders/some%20builder/builds/?select=-1&select=-2', {
1691                 [-1]: MockData.runningBuild({builder: 'some builder', buildRequestId: 2}),
1692                 [-2]: MockData.finishedBuild({builder: 'some builder', buildRequestId: 1}),
1693             });
1694             assertAndResolveRequest(requests[12], 'GET', '/json/builders/other%20builder/builds/?select=-1&select=-2', {});
1695             return syncPromise;
1696         }).then(() => {
1697             return TestGroup.fetchForTask(taskId, true);
1698         }).then((testGroups) => {
1699             assert.equal(testGroups.length, 1);
1700             const testGroup = testGroups[0];
1701             const webkit = Repository.findById(MockData.webkitRepositoryId());
1702             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1703             assert.equal(testGroup.buildRequests().length, 6);
1704
1705             const buildRequest = testGroup.buildRequests()[0];
1706             assert(buildRequest.isBuild());
1707             assert(!buildRequest.isTest());
1708             assert.equal(buildRequest.statusLabel(), 'Completed');
1709             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1710             assert.notEqual(buildRequest.buildId(), null);
1711
1712             const commitSet = buildRequest.commitSet();
1713             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1714             assert.equal(commitSet.patchForRepository(webkit), null);
1715             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1716             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1717             const webkitRoot = commitSet.rootForRepository(webkit);
1718             assert(webkitRoot instanceof UploadedFile);
1719             assert.equal(webkitRoot.filename(), 'root123.dat');
1720             const jscRoot = commitSet.rootForRepository(ownedJSC);
1721             assert(jscRoot instanceof UploadedFile);
1722             assert.equal(jscRoot.filename(), 'root123.dat');
1723             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1724
1725             const otherBuildRequest = testGroup.buildRequests()[1];
1726             assert(otherBuildRequest.isBuild());
1727             assert(!otherBuildRequest.isTest());
1728             assert.equal(otherBuildRequest.statusLabel(), 'Running');
1729             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1730             assert.equal(otherBuildRequest.buildId(), null);
1731
1732             const otherCommitSet = otherBuildRequest.commitSet();
1733             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1734             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1735             assert.equal(otherCommitSet.rootForRepository(webkit), null);
1736             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1737             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1738             assert.deepEqual(otherCommitSet.allRootFiles(), []);
1739
1740             return uploadRoot(otherBuildRequest.id(), 124);
1741         }).then(() => {
1742             return TestGroup.fetchForTask(taskId, true);
1743         }).then((testGroups) => {
1744             assert.equal(testGroups.length, 1);
1745             const testGroup = testGroups[0];
1746             const webkit = Repository.findById(MockData.webkitRepositoryId());
1747             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1748             assert.equal(testGroup.buildRequests().length, 6);
1749
1750             const buildRequest = testGroup.buildRequests()[0];
1751             assert(buildRequest.isBuild());
1752             assert(!buildRequest.isTest());
1753             assert.equal(buildRequest.statusLabel(), 'Completed');
1754             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1755             assert.notEqual(buildRequest.buildId(), null);
1756
1757             const commitSet = buildRequest.commitSet();
1758             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1759             assert.equal(commitSet.patchForRepository(webkit), null);
1760             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1761             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1762             const webkitRoot = commitSet.rootForRepository(webkit);
1763             assert(webkitRoot instanceof UploadedFile);
1764             assert.equal(webkitRoot.filename(), 'root123.dat');
1765             const jscRoot = commitSet.rootForRepository(ownedJSC);
1766             assert(jscRoot instanceof UploadedFile);
1767             assert.equal(jscRoot.filename(), 'root123.dat');
1768             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1769
1770             const otherBuildRequest = testGroup.buildRequests()[1];
1771             assert(otherBuildRequest.isBuild());
1772             assert(!otherBuildRequest.isTest());
1773             assert.equal(otherBuildRequest.statusLabel(), 'Running');
1774             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1775             assert.equal(otherBuildRequest.buildId(), null);
1776
1777             const otherCommitSet = otherBuildRequest.commitSet();
1778             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1779             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1780             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1781             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1782             const otherWebkitRoot = otherCommitSet.rootForRepository(webkit);
1783             assert(otherWebkitRoot instanceof UploadedFile);
1784             assert.equal(otherWebkitRoot.filename(), 'root124.dat');
1785             assert.deepEqual(otherCommitSet.allRootFiles(), [otherWebkitRoot]);
1786             return uploadRoot(otherBuildRequest.id(), 124, [{ownerRepository: 'WebKit', ownedRepository: 'JavaScriptCore'}], '2017-05-10T02:54:09.666');
1787         }).then(() => {
1788             return TestGroup.fetchForTask(taskId, true);
1789         }).then((testGroups) => {
1790             assert.equal(testGroups.length, 1);
1791             const testGroup = testGroups[0];
1792             const webkit = Repository.findById(MockData.webkitRepositoryId());
1793             const ownedJSC = Repository.findById(MockData.ownedJSCRepositoryId());
1794             assert.equal(testGroup.buildRequests().length, 6);
1795
1796             const buildRequest = testGroup.buildRequests()[0];
1797             assert(buildRequest.isBuild());
1798             assert(!buildRequest.isTest());
1799             assert.equal(buildRequest.statusLabel(), 'Completed');
1800             assert.equal(buildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1801             assert.notEqual(buildRequest.buildId(), null);
1802
1803             const commitSet = buildRequest.commitSet();
1804             assert.equal(commitSet.revisionForRepository(webkit), '191622');
1805             assert.equal(commitSet.patchForRepository(webkit), null);
1806             assert.equal(commitSet.ownerRevisionForRepository(webkit), null);
1807             assert.equal(commitSet.ownerRevisionForRepository(ownedJSC), commitSet.revisionForRepository(webkit));
1808             const webkitRoot = commitSet.rootForRepository(webkit);
1809             assert(webkitRoot instanceof UploadedFile);
1810             assert.equal(webkitRoot.filename(), 'root123.dat');
1811             const jscRoot = commitSet.rootForRepository(ownedJSC);
1812             assert(jscRoot instanceof UploadedFile);
1813             assert.equal(jscRoot.filename(), 'root123.dat');
1814             assert.deepEqual(commitSet.allRootFiles(), [webkitRoot, jscRoot]);
1815
1816             const otherBuildRequest = testGroup.buildRequests()[1];
1817             assert(otherBuildRequest.isBuild());
1818             assert(!otherBuildRequest.isTest());
1819             assert.equal(otherBuildRequest.statusLabel(), 'Completed');
1820             assert.equal(otherBuildRequest.statusUrl(), 'http://build.webkit.org/builders/some%20builder/builds/124');
1821             assert.notEqual(otherBuildRequest.buildId(), null);
1822
1823             const otherCommitSet = otherBuildRequest.commitSet();
1824             assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
1825             assert.equal(otherCommitSet.patchForRepository(webkit), null);
1826             assert.equal(otherCommitSet.ownerRevisionForRepository(webkit), null);
1827             assert.equal(otherCommitSet.ownerRevisionForRepository(ownedJSC), otherCommitSet.revisionForRepository(webkit));
1828             const otherWebkitRoot = otherCommitSet.rootForRepository(webkit);
1829             assert(otherWebkitRoot instanceof UploadedFile);
1830             assert.equal(otherWebkitRoot.filename(), 'root124.dat');
1831             const otherJSCRoot = otherCommitSet.rootForRepository(ownedJSC);
1832             assert(otherJSCRoot instanceof UploadedFile);
1833             assert.equal(otherJSCRoot.filename(), 'root124.dat');
1834             assert.deepEqual(otherCommitSet.allRootFiles(), [otherWebkitRoot, otherJSCRoot]);
1835         });
1836     });
1837 });