Update Perf buildbot syncing scripts for Buildbot 0.9
[WebKit.git] / Websites / perf.webkit.org / server-tests / resources / mock-data.js
1 require('../../tools/js/v3-models.js');
2
3 var crypto = require('crypto');
4
5 MockData = {
6     resetV3Models: function ()
7     {
8         Manifest.reset();
9     },
10     emptyTriggeragbleId() { return 1001; },
11     someTestId() { return 200; },
12     somePlatformId() { return 65; },
13     otherPlatformId() { return 101; },
14     macosRepositoryId() { return 9; },
15     webkitRepositoryId() { return 11; },
16     ownedJSCRepositoryId() { return 213; },
17     jscRepositoryId() { return 222; },
18     gitWebkitRepositoryId() { return 111; },
19     sharedRepositoryId() { return 14; },
20     buildbotBuildersURLDeprecated() {return '/json/builders'},
21     buildbotBuildersURL() {return '/api/v2/builders'},
22     pendingBuildsUrl: function (builderName) {
23         const builderId = this.builderIDForName(builderName);
24         return `/api/v2/builders/${builderId}/buildrequests?complete=false&claimed=false&property=*`;
25     },
26     recentBuildsUrl: function (builderName, count) {
27         const builderId = this.builderIDForName(builderName);
28         return `/api/v2/builders/${builderId}/builds?limit=${count}&order=-number&property=*`; 
29     },
30     statusUrl: function (builderName, buildId) {
31         const builderId = this.builderIDForName(builderName);
32         return `http://build.webkit.org/#/builders/${builderId}/builds/${buildId}`; 
33     },
34     addMockConfiguration: function (db)
35     {
36         return Promise.all([
37             db.insert('build_triggerables', {id: 1000, name: 'build-webkit'}),
38             db.insert('build_slaves', {id: 20, name: 'sync-slave', password_hash: crypto.createHash('sha256').update('password').digest('hex')}),
39             db.insert('repositories', {id: this.macosRepositoryId(), name: 'macOS'}),
40             db.insert('repositories', {id: this.webkitRepositoryId(), name: 'WebKit'}),
41             db.insert('repositories', {id: this.sharedRepositoryId(), name: 'Shared'}),
42             db.insert('repositories', {id: this.ownedJSCRepositoryId(), owner: this.webkitRepositoryId(), name: 'JavaScriptCore'}),
43             db.insert('repositories', {id: this.jscRepositoryId(), name: 'JavaScriptCore'}),
44             db.insert('triggerable_repository_groups', {id: 2001, name: 'webkit-svn', triggerable: 1000}),
45             db.insert('triggerable_repositories', {repository: this.macosRepositoryId(), group: 2001}),
46             db.insert('triggerable_repositories', {repository: this.webkitRepositoryId(), group: 2001}),
47             db.insert('commits', {id: 87832, repository: this.macosRepositoryId(), revision: '10.11 15A284'}),
48             db.insert('commits', {id: 93116, repository: this.webkitRepositoryId(), revision: '191622', time: (new Date(1445945816878)).toISOString()}),
49             db.insert('commits', {id: 96336, repository: this.webkitRepositoryId(), revision: '192736', time: (new Date(1448225325650)).toISOString()}),
50             db.insert('commits', {id: 111168, repository: this.sharedRepositoryId(), revision: '80229', time: '2016-03-02T23:17:54.3Z'}),
51             db.insert('commits', {id: 111169, repository: this.sharedRepositoryId(), revision: '80230', time: '2016-03-02T23:37:18.0Z'}),
52             db.insert('commits', {id: 11797, repository: this.jscRepositoryId(), revision: 'jsc-6161', time: '2016-03-02T23:19:55.3Z'}),
53             db.insert('commits', {id: 12017, repository: this.jscRepositoryId(), revision: 'jsc-9191', time: '2016-05-02T23:13:57.1Z'}),
54             db.insert('commits', {id: 1797, repository: this.ownedJSCRepositoryId(), revision: 'owned-jsc-6161', time: '2016-03-02T23:19:55.3Z'}),
55             db.insert('commits', {id: 2017, repository: this.ownedJSCRepositoryId(), revision: 'owned-jsc-9191', time: '2016-05-02T23:13:57.1Z'}),
56             db.insert('commit_ownerships', {owner: 93116, owned: 1797}),
57             db.insert('commit_ownerships', {owner: 96336, owned: 2017}),
58             db.insert('builds', {id: 901, number: '901', time: '2015-10-27T12:05:27.1Z'}),
59             db.insert('platforms', {id: MockData.somePlatformId(), name: 'some platform'}),
60             db.insert('platforms', {id: MockData.otherPlatformId(), name: 'other platform'}),
61             db.insert('tests', {id: MockData.someTestId(), name: 'some test'}),
62             db.insert('test_metrics', {id: 300, test: 200, name: 'some metric'}),
63             db.insert('test_configurations', {id: 301, metric: 300, platform: MockData.somePlatformId(), type: 'current'}),
64             db.insert('test_configurations', {id: 302, metric: 300, platform: MockData.otherPlatformId(), type: 'current'}),
65             db.insert('test_runs', {id: 801, config: 301, build: 901, mean_cache: 100}),
66         ]);
67     },
68     addMockData: function (db, statusList)
69     {
70         if (!statusList)
71             statusList = ['pending', 'pending', 'pending', 'pending'];
72         return Promise.all([
73             this.addMockConfiguration(db),
74             db.insert('commit_sets', {id: 401}),
75             db.insert('commit_set_items', {set: 401, commit: 87832}),
76             db.insert('commit_set_items', {set: 401, commit: 93116}),
77             db.insert('commit_sets', {id: 402}),
78             db.insert('commit_set_items', {set: 402, commit: 87832}),
79             db.insert('commit_set_items', {set: 402, commit: 96336}),
80             db.insert('analysis_tasks', {id: 500, platform: 65, metric: 300, name: 'some task',
81                 start_run: 801, start_run_time: '2015-10-27T12:05:27.1Z',
82                 end_run: 801, end_run_time: '2015-10-27T12:05:27.1Z'}),
83             db.insert('analysis_test_groups', {id: 600, task: 500, name: 'some test group'}),
84             db.insert('build_requests', {id: 700, status: statusList[0], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 600, order: 0, commit_set: 401}),
85             db.insert('build_requests', {id: 701, status: statusList[1], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 600, order: 1, commit_set: 402}),
86             db.insert('build_requests', {id: 702, status: statusList[2], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 600, order: 2, commit_set: 401}),
87             db.insert('build_requests', {id: 703, status: statusList[3], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 600, order: 3, commit_set: 402}),
88         ]);
89     },
90     addAnotherTriggerable(db) {
91         return Promise.all([
92             db.insert('build_triggerables', {id: 2345, name: 'build-webkit-jsc'}),
93             db.insert('triggerable_repository_groups', {id: 4002, name: 'mac-svnwebkit-jsc', triggerable: 2345}),
94             db.insert('triggerable_repositories', {repository: this.macosRepositoryId(), group: 4002}),
95             db.insert('triggerable_repositories', {repository: this.webkitRepositoryId(), group: 4002}),
96             db.insert('triggerable_repositories', {repository: this.jscRepositoryId(), group: 4002}),
97         ]);
98     },
99     addEmptyTriggerable(db)
100     {
101         return Promise.all([
102             db.insert('build_triggerables', {id: this.emptyTriggeragbleId(), name: 'empty-triggerable'}),
103             db.insert('repositories', {id: this.macosRepositoryId(), name: 'macOS'}),
104             db.insert('repositories', {id: this.webkitRepositoryId(), name: 'WebKit'}),
105             db.insert('repositories', {id: this.gitWebkitRepositoryId(), name: 'Git-WebKit'}),
106             db.insert('platforms', {id: MockData.somePlatformId(), name: 'some platform'}),
107             db.insert('tests', {id: MockData.someTestId(), name: 'some test'}),
108             db.insert('test_metrics', {id: 5300, test: MockData.someTestId(), name: 'some metric'}),
109             db.insert('test_configurations', {id: 5400, metric: 5300, platform: MockData.somePlatformId(), type: 'current'}),
110         ]);
111     },
112     addMockTestGroupWithGitWebKit(db)
113     {
114         return Promise.all([
115             db.insert('repositories', {id: this.gitWebkitRepositoryId(), name: 'Git-WebKit'}),
116             db.insert('triggerable_repository_groups', {id: 2002, name: 'webkit-git', triggerable: 1000}),
117             db.insert('triggerable_repositories', {repository: this.macosRepositoryId(), group: 2002}),
118             db.insert('triggerable_repositories', {repository: this.gitWebkitRepositoryId(), group: 2002}),
119             db.insert('commits', {id: 193116, repository: this.gitWebkitRepositoryId(), revision: '2ceda45d3cd63cde58d0dbf5767714e03d902e43', time: (new Date(1445945816878)).toISOString()}),
120             db.insert('commits', {id: 196336, repository: this.gitWebkitRepositoryId(), revision: '8e294365a452a89785d6536ca7f0fc8a95fa152d', time: (new Date(1448225325650)).toISOString()}),
121             db.insert('commit_sets', {id: 1401}),
122             db.insert('commit_set_items', {set: 1401, commit: 87832}),
123             db.insert('commit_set_items', {set: 1401, commit: 193116}),
124             db.insert('commit_sets', {id: 1402}),
125             db.insert('commit_set_items', {set: 1402, commit: 87832}),
126             db.insert('commit_set_items', {set: 1402, commit: 196336}),
127             db.insert('analysis_test_groups', {id: 1600, task: 500, name: 'test group with git'}),
128             db.insert('build_requests', {id: 1700, status: 'pending', triggerable: 1000, repository_group: 2002, platform: 65, test: 200, group: 1600, order: 0, commit_set: 1401}),
129             db.insert('build_requests', {id: 1701, status: 'pending', triggerable: 1000, repository_group: 2002, platform: 65, test: 200, group: 1600, order: 1, commit_set: 1402}),
130             db.insert('build_requests', {id: 1702, status: 'pending', triggerable: 1000, repository_group: 2002, platform: 65, test: 200, group: 1600, order: 2, commit_set: 1401}),
131             db.insert('build_requests', {id: 1703, status: 'pending', triggerable: 1000, repository_group: 2002, platform: 65, test: 200, group: 1600, order: 3, commit_set: 1402}),
132         ]);
133     },
134     addAnotherMockTestGroup: function (db, statusList, author)
135     {
136         if (!statusList)
137             statusList = ['pending', 'pending', 'pending', 'pending'];
138         const test = MockData.someTestId();
139         const triggerable = 1000;
140         const platform = 65;
141         const repository_group = 2001;
142         return Promise.all([
143             db.insert('analysis_test_groups', {id: 601, task: 500, name: 'another test group', author}),
144             db.insert('build_requests', {id: 713, status: statusList[3], triggerable, repository_group, platform, test, group: 601, order: 3, commit_set: 402}),
145             db.insert('build_requests', {id: 710, status: statusList[0], triggerable, repository_group, platform, test, group: 601, order: 0, commit_set: 401}),
146             db.insert('build_requests', {id: 712, status: statusList[2], triggerable, repository_group, platform, test, group: 601, order: 2, commit_set: 401}),
147             db.insert('build_requests', {id: 711, status: statusList[1], triggerable, repository_group, platform, test, group: 601, order: 1, commit_set: 402}),
148         ]);
149     },
150     addTestGroupWithOwnedCommits(db, statusList)
151     {
152
153         if (!statusList)
154             statusList = ['pending', 'pending', 'pending', 'pending'];
155         return Promise.all([
156             this.addMockConfiguration(db),
157             this.addAnotherTriggerable(db),
158             db.insert('analysis_tasks', {id: 1080, platform: 65, metric: 300, name: 'some task with component test',
159                 start_run: 801, start_run_time: '2015-10-27T12:05:27.1Z',
160                 end_run: 801, end_run_time: '2015-10-27T12:05:27.1Z'}),
161             db.insert('analysis_test_groups', {id: 900, task: 1080, name: 'some test group with component test'}),
162             db.insert('commit_sets', {id: 403}),
163             db.insert('commit_set_items', {set: 403, commit: 87832}),
164             db.insert('commit_set_items', {set: 403, commit: 93116}),
165             db.insert('commit_set_items', {set: 403, commit: 1797, commit_owner: 93116, requires_build: true}),
166             db.insert('commit_sets', {id: 404}),
167             db.insert('commit_set_items', {set: 404, commit: 87832}),
168             db.insert('commit_set_items', {set: 404, commit: 96336}),
169             db.insert('commit_set_items', {set: 404, commit: 2017, commit_owner: 96336, requires_build: true}),
170             db.insert('build_requests', {id: 704, status: statusList[0], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 0, commit_set: 403}),
171             db.insert('build_requests', {id: 705, status: statusList[1], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 1, commit_set: 404}),
172             db.insert('build_requests', {id: 706, status: statusList[2], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 2, commit_set: 403}),
173             db.insert('build_requests', {id: 707, status: statusList[3], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 3, commit_set: 404}),
174         ]);
175     },
176     addTestGroupWithOwnerCommitNotInCommitSet(db)
177     {
178         return Promise.all([
179             this.addMockConfiguration(db),
180             this.addAnotherTriggerable(db),
181             db.insert('analysis_tasks', {id: 1080, platform: 65, metric: 300, name: 'some task with component test',
182                 start_run: 801, start_run_time: '2015-10-27T12:05:27.1Z',
183                 end_run: 801, end_run_time: '2015-10-27T12:05:27.1Z'}),
184             db.insert('analysis_test_groups', {id: 900, task: 1080, name: 'some test group with component test'}),
185             db.insert('commit_sets', {id: 404}),
186             db.insert('commit_set_items', {set: 404, commit: 87832}),
187             db.insert('commit_set_items', {set: 404, commit: 96336}),
188             db.insert('commit_set_items', {set: 404, commit: 2017, commit_owner: 93116, requires_build: true}),
189             db.insert('build_requests', {id: 704, status: 'pending', triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 0, commit_set: 404}),
190         ]);
191     },
192     mockTestSyncConfigWithSingleBuilder: function ()
193     {
194         return {
195             'triggerableName': 'build-webkit',
196             'lookbackCount': 2,
197             'buildRequestArgument': 'build-request-id',
198             'repositoryGroups': {
199                 'webkit-svn': {
200                     'repositories': {'WebKit': {}, 'macOS': {}},
201                     'testProperties': {
202                         'os': {'revision': 'macOS'},
203                         'wk': {'revision': 'WebKit'},
204                     }
205                 }
206             },
207             'types': {
208                 'some-test': {'test': ['some test']}
209             },
210             'builders': {
211                 'builder-1': {'builder': 'some-builder-1',
212                      properties: {forcescheduler: 'force-some-builder-1'}}
213             },
214             'testConfigurations': [
215                 {
216                     'platforms': ['some platform'],
217                     'types': ['some-test'],
218                     'builders': ['builder-1'],
219                 }
220             ]
221         }
222     },
223     mockTestSyncConfigWithTwoBuilders: function ()
224     {
225         return {
226             'triggerableName': 'build-webkit',
227             'lookbackCount': 2,
228             'buildRequestArgument': 'build-request-id',
229             'repositoryGroups': {
230                 'webkit-svn': {
231                     'repositories': {'WebKit': {}, 'macOS': {}},
232                     'testProperties': {
233                         'os': {'revision': 'macOS'},
234                         'wk': {'revision': 'WebKit'},
235                     }
236                 }
237             },
238             'types': {
239                 'some-test': {'test': ['some test']},
240             },
241             'builders': {
242                 'builder-1': {'builder': 'some-builder-1', properties: {forcescheduler: 'force-some-builder-1'}},
243                 'builder-2': {'builder': 'some builder 2', properties: {forcescheduler: 'force-some-builder-2'}},
244             },
245             'testConfigurations': [
246                 {
247                     'platforms': ['some platform'],
248                     'types': ['some-test'],
249                     'builders': ['builder-1', 'builder-2'],
250                 }
251             ]
252         }
253     },
254     mockBuildbotBuildersDeprecated: function ()
255     {
256         return {
257             "some builder": {
258                 "slaves": [ "some-slave-1" ]
259             },
260             "some-builder-1": {
261                 "slaves": [ "some-slave-2" ]
262             },
263             "some builder 2": {
264                 "slaves": [ "some-slave-3" ]
265             },
266             "other builder": {
267                 "slaves": [ "some-slave-4" ]
268             },
269             "some tester": {
270                 "slaves": [ "some-slave-5" ]
271             },
272             "another tester": {
273                 "slaves": [ "some-slave-6" ]
274             }
275         }
276     },
277     mockBuildbotBuilders: function ()
278     {
279         return {
280             "builders": [
281                 {
282                     "builderid": 1,
283                     "name": "some builder",
284                 },
285                 {
286                     "builderid": 2,
287                     "name": "some-builder-1",
288                 },
289                 {
290                     "builderid": 3,
291                     "name": "some builder 2",
292                 },
293                 {
294                     "builderid": 4,
295                     "name": "other builder",
296                 },
297                 {
298                     "builderid": 5,
299                     "name": "some tester",
300                 },
301                 {
302                     "builderid": 6,
303                     "name": "another tester",
304                 }
305             ]
306         }
307     },
308     builderIDForName: function(builderName)
309     {
310         for (let builder of this.mockBuildbotBuilders().builders) {
311             if (builder.name == builderName)
312                 return builder.builderid;
313         }
314         return -1;
315     },
316     pendingBuildData(options)
317     {
318         return {
319             "builderid": options.builderId || 2,
320             "buildrequestid": options.buildbotBuildRequestId || 18,
321             "buildsetid": 894720,
322             "claimed": false,
323             "claimed_at": null,
324             "claimed_by_masterid": null,
325             "complete": false,
326             "complete_at": null,
327             "priority": 0,
328             "results": -1,
329             "submitted_at": options.buildTime || (new Date('2016-03-23T03:49:43Z') / 1000),
330             "waited_for": false,
331             "properties": {
332                 "build-request-id": [(options.buildRequestId || 702).toString(), "Force Build Form"],
333                 "scheduler": ["ABTest-iPad-RunBenchmark-Tests-ForceScheduler", "Scheduler"],
334                 "wk": [options.webkitRevision || '191622', "Unknown"],
335                 "os": [options.osxRevision || '10.11 15A284', "Unknown"],
336                 "slavename": [options.workerName || "bot202", "Worker (deprecated)"],
337                 "workername": [options.workerName || "bot202", "Worker"]
338             }
339         };
340     },
341     pendingBuild(options)
342     {
343         options = options || {};
344         return {
345             "buildrequests": [this.pendingBuildData(options)]
346         };
347     },
348     pendingBuildDeprecated(options)
349     {
350         options = options || {};
351         return {
352             'builderName': options.builder || 'some-builder-1',
353             'builds': [],
354             'properties': [
355                 ['wk', options.webkitRevision || '191622'],
356                 ['os', options.osxRevision || '10.11 15A284'],
357                 ['build-request-id', (options.buildRequestId || 702).toString(), ]
358             ],
359             'source': {
360                 'branch': '',
361                 'changes': [],
362                 'codebase': 'WebKit',
363                 'hasPatch': false,
364                 'project': '',
365                 'repository': '',
366                 'revision': ''
367             },
368         };
369     },
370     sampleBuildData(options, overrides)
371     {
372         options = options || {};
373         overrides = overrides || {};
374         return {
375             "builderid": options.builderId || 2,
376             "number":  options.buildNumber || 124, 
377             "buildrequestid": options.buildbotBuildRequestId || 19,
378             "complete": 'isComplete' in overrides ? overrides.isComplete : (options.isComplete || false),
379             "complete_at": null,
380             "buildid": options.buildid || 418744,
381             "masterid": 1,
382             "results": null,
383             "started_at": new Date('2017-12-19T23:11:49Z') / 1000,
384             "state_string": "building",
385             "workerid": 41,
386             "properties": {
387                 "build-request-id": [(options.buildRequestId || 701).toString(), "Force Build Form"],
388                 "os": [options.osxRevision || '10.11 15A284', "Unknown"],
389                 "wk": [options.webkitRevision || '192736', "Unknown"],
390                 "project": ['', "Unknown"],
391                 "repository": ['', "Unknown"],
392                 "revision": ['', "Unknown"],
393                 "slavename": [options.workerName || "bot202", "Worker (deprecated)"],
394                 "workername": [options.workerName || "bot202", "Worker"]
395             }
396         };   
397     },
398     runningBuildData(options)
399     {
400         return this.sampleBuildData(options);
401     },
402     runningBuild(options)
403     {
404         return {
405             "builds": [this.runningBuildData(options)]
406         };
407     },
408     runningBuildDeprecated(options)
409     {
410         options = options || {};
411         return {
412             'builderName': options.builder || 'some-builder-1',
413             'builds': [],
414             'properties': [
415                 ['wk', options.webkitRevision || '192736'],
416                 ['os', options.osxRevision || '10.11 15A284'],
417                 ['build-request-id', (options.buildRequestId || 701).toString(), ]
418             ],
419             'currentStep': {},
420             'eta': 721,
421             'number': options.buildNumber || 124,
422             'source': {
423                 'branch': '',
424                 'changes': [],
425                 'codebase': 'WebKit',
426                 'hasPatch': false,
427                 'project': '',
428                 'repository': '',
429                 'revision': ''
430             },
431         };
432     },
433     finishedBuildData(options)
434     {
435         options = options || {};
436         if (!options.buildRequestId)
437             options.buildRequestId = 700;
438         if (!options.buildNumber)
439             options.buildNumber = 123;
440         if (!options.webkitRevision)
441             options.webkitRevision = '191622';
442         return this.sampleBuildData(options, {isComplete: true});
443     },
444     finishedBuild(options)
445     {
446         return {
447             "builds": [this.finishedBuildData(options)]
448         };
449     },
450     finishedBuildDeprecated(options)
451     {
452         options = options || {};
453         return {
454             'builderName': options.builder || 'some-builder-1',
455             'builds': [],
456             'properties': [
457                 ['wk', options.webkitRevision || '191622'],
458                 ['os', options.osxRevision || '10.11 15A284'],
459                 ['build-request-id', (options.buildRequestId || 700).toString(), ]
460             ],
461             'currentStep': null,
462             'eta': null,
463             'number': options.buildNumber || 123,
464             'source': {
465                 'branch': '',
466                 'changes': [],
467                 'codebase': 'WebKit',
468                 'hasPatch': false,
469                 'project': '',
470                 'repository': '',
471                 'revision': ''
472             },
473             'times': [0, 1],
474         };
475     }
476 }
477
478 if (typeof module != 'undefined')
479     module.exports = MockData;