Loading the perf dashboard takes multiple seconds
[WebKit-https.git] / Websites / perf.webkit.org / tests / admin-reprocess-report.js
1 describe("/admin/reprocess-report", function () {
2     var simpleReport = [{
3         "buildNumber": "1986",
4         "buildTime": "2013-02-28T10:12:03",
5         "builderName": "someBuilder",
6         "builderPassword": "somePassword",
7         "platform": "Mountain Lion",
8         "tests": {
9                 "test": {
10                     "metrics": {"FrameRate": { "current": [[1, 2, 3], [4, 5, 6]] }}
11                 },
12             },
13         }];
14
15     function addBuilder(report, callback) {
16         queryAndFetchAll('INSERT INTO builders (builder_name, builder_password_hash) values ($1, $2)',
17             [report[0].builderName, sha256(report[0].builderPassword)], callback);
18     }
19
20     it("should add build", function () {
21         addBuilder(simpleReport, function () {
22             postJSON('/api/report/', simpleReport, function (response) {
23                 assert.equal(response.statusCode, 200);
24                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
25                 queryAndFetchAll('SELECT * FROM builds', [], function (buildRows) {
26                     assert.equal(buildRows.length, 1);
27                     assert.equal(buildRows[0]['build_number'], 1986);
28                     queryAndFetchAll('SELECT * FROM reports', [], function (reportRows) {
29                         assert.equal(reportRows.length, 1);
30                         assert.equal(reportRows[0]['report_build_number'], 1986);
31                         queryAndFetchAll('UPDATE reports SET report_build = NULL; DELETE FROM builds; SELECT * FROM builds', [], function (buildRows) {
32                             assert.equal(buildRows.length, 0);
33                             var reportId = reportRows[0]['report_id'];
34                             httpGet('/admin/reprocess-report?report=' + reportId, function (response) {
35                                 assert.equal(response.statusCode, 200);
36                                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
37                                 queryAndFetchAll('SELECT * FROM builds', [], function (buildRows) {
38                                     assert.equal(buildRows.length, 1);
39                                     assert.equal(buildRows[0]['build_number'], 1986);
40                                     notifyDone();
41                                 });
42                             });
43                         });
44                     });
45                 });
46             });
47         });
48     });
49
50     it("should not duplicate the reprocessed report", function () {
51         addBuilder(simpleReport, function () {
52             postJSON('/api/report/', simpleReport, function (response) {
53                 assert.equal(response.statusCode, 200);
54                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
55                 queryAndFetchAll('SELECT * FROM reports', [], function (originalReprotRows) {
56                     assert.equal(originalReprotRows.length, 1);
57                     queryAndFetchAll('UPDATE reports SET report_build = NULL; DELETE FROM builds', [], function () {
58                         httpGet('/admin/reprocess-report?report=' + originalReprotRows[0]['report_id'], function (response) {
59                             assert.equal(response.statusCode, 200);
60                             assert.equal(JSON.parse(response.responseText)['status'], 'OK');
61                             queryAndFetchAll('SELECT * FROM reports', [], function (reportRows) {
62                                 originalReprotRows[0]['report_committed_at'] = null;
63                                 reportRows[0]['report_committed_at'] = null;
64                                 assert.notEqual(originalReprotRows[0]['report_build'], reportRows[0]['report_build']);
65                                 originalReprotRows[0]['report_build'] = null;
66                                 reportRows[0]['report_build'] = null;
67                                 assert.deepEqual(reportRows, originalReprotRows);
68                                 notifyDone();
69                             });
70                         });
71                     });
72                 });
73             });
74         });
75     });
76 });