Migrate legacy perf dashboard tests to mocha.js based tests
[WebKit-https.git] / Websites / perf.webkit.org / server-tests / admin-platforms-tests.js
1 'use strict';
2
3 const assert = require('assert');
4
5 const TestServer = require('./resources/test-server.js');
6 const connectToDatabaseInEveryTest = require('./resources/common-operations.js').connectToDatabaseInEveryTest;
7 const submitReport = require('./resources/common-operations.js').submitReport;
8
9 describe("/admin/platforms", function () {
10     this.timeout(1000);
11     TestServer.inject();
12     connectToDatabaseInEveryTest();
13
14     function reportsForDifferentPlatforms()
15     {
16         return [
17             {
18                 "buildNumber": "3001",
19                 "buildTime": "2013-02-28T09:01:47",
20                 "builderName": "someBuilder",
21                 "builderPassword": "somePassword",
22                 "platform": "Mavericks",
23                 "tests": {"test": { "metrics": {"FrameRate": { "current": [[1, 1, 1], [1, 1, 1]] } } } },
24             },
25             {
26                 "buildNumber": "3001",
27                 "buildTime": "2013-02-28T10:12:03",
28                 "builderName": "someBuilder",
29                 "builderPassword": "somePassword",
30                 "platform": "Mountain Lion",
31                 "tests": {"test": { "metrics": {"FrameRate": { "current": [[2, 2, 2], [2, 2, 2]] }, "Combined": { "current": [[3, 3, 3], [3, 3, 3]] }} } },
32             },
33             {
34                 "buildNumber": "3003",
35                 "buildTime": "2013-02-28T12:56:26",
36                 "builderName": "someBuilder",
37                 "builderPassword": "somePassword",
38                 "platform": "Trunk Mountain Lion",
39                 "tests": {"test": { "metrics": {"FrameRate": { "current": [[4, 4, 4], [4, 4, 4]] } } } }
40             }];
41     } 
42
43     it("should delete the platform that got merged into another one", function (done) {
44         const db = TestServer.database();
45         let oldPlatforms;        
46         submitReport(reportsForDifferentPlatforms()).then(function () {
47             return db.selectAll('platforms', 'name');
48         }).then(function (platforms) {
49             oldPlatforms = platforms;
50             assert.equal(oldPlatforms.length, 3);
51             assert.equal(oldPlatforms[0]['name'], 'Mavericks');
52             assert.equal(oldPlatforms[1]['name'], 'Mountain Lion');
53             assert.equal(oldPlatforms[2]['name'], 'Trunk Mountain Lion');
54         }).then(function () {
55             return TestServer.remoteAPI().postFormUrlencodedData('/admin/platforms.php',
56                 {'action': 'merge', 'id': oldPlatforms[1]['id'], 'destination': oldPlatforms[2]['id']});
57         }).then(function () {
58             return db.selectAll('platforms');
59         }).then(function (newPlatforms) {
60             assert.equal(newPlatforms.length, 2);
61             assert.deepEqual(newPlatforms[0], oldPlatforms[0]);
62             assert.deepEqual(newPlatforms[1], oldPlatforms[2]);
63             done();
64         }).catch(done);
65     });
66
67     it("should move test runs from the merged platform to the destination platform", function (done) {
68         let oldTestRuns;
69         const queryForRuns = 'SELECT * FROM test_runs, test_configurations, platforms WHERE run_config = config_id AND config_platform = platform_id ORDER by run_mean_cache';
70         const db = TestServer.database();
71         submitReport(reportsForDifferentPlatforms()).then(function () {
72             return db.query(queryForRuns);
73         }).then(function (result) {
74             oldTestRuns = result.rows;
75             assert.equal(oldTestRuns.length, 4);
76             assert.equal(oldTestRuns[0]['platform_name'], 'Mavericks');
77             assert.equal(oldTestRuns[0]['run_sum_cache'], 6);
78             assert.equal(oldTestRuns[1]['platform_name'], 'Mountain Lion');
79             assert.equal(oldTestRuns[1]['run_sum_cache'], 12);
80             assert.equal(oldTestRuns[2]['platform_name'], 'Mountain Lion');
81             assert.equal(oldTestRuns[2]['run_sum_cache'], 18);
82             assert.equal(oldTestRuns[3]['platform_name'], 'Trunk Mountain Lion');
83             assert.equal(oldTestRuns[3]['run_sum_cache'], 24);
84         }).then(function () {
85             return TestServer.remoteAPI().postFormUrlencodedData('/admin/platforms.php',
86                 {'action': 'merge', 'id': oldTestRuns[1]['platform_id'], 'destination': oldTestRuns[3]['platform_id']});
87         }).then(function () {
88             return db.query(queryForRuns);
89         }).then(function (result) {
90             const newTestRuns = result.rows;
91             assert.equal(newTestRuns.length, 4);
92             assert.equal(newTestRuns[0]['run_id'], oldTestRuns[0]['run_id']);
93             assert.equal(newTestRuns[0]['platform_name'], 'Mavericks');
94             assert.equal(newTestRuns[0]['run_sum_cache'], 6);
95             assert.equal(newTestRuns[1]['run_id'], oldTestRuns[1]['run_id']);
96             assert.equal(newTestRuns[1]['platform_name'], 'Trunk Mountain Lion');
97             assert.equal(newTestRuns[1]['run_sum_cache'], 12);
98             assert.equal(newTestRuns[2]['run_id'], oldTestRuns[2]['run_id']);
99             assert.equal(newTestRuns[2]['platform_name'], 'Trunk Mountain Lion');
100             assert.equal(newTestRuns[2]['run_sum_cache'], 18);
101             assert.equal(newTestRuns[3]['run_id'], oldTestRuns[3]['run_id']);
102             assert.equal(newTestRuns[3]['platform_name'], 'Trunk Mountain Lion');
103             assert.equal(newTestRuns[3]['run_sum_cache'], 24);
104             assert.equal(newTestRuns[1]['run_config'], newTestRuns[3]['run_config']);
105             done();
106         }).catch(done);
107     });
108
109     it("should move test configurations from the merged platform to the destination platform", function (done) {
110         let oldConfigs;
111         const reports = reportsForDifferentPlatforms();
112         reports[0]['tests'] = {"test": { "metrics": {"FrameRate": { "baseline": [[1, 1, 1], [1, 1, 1]] } } } };
113         const queryForConfig = 'SELECT * from test_configurations, platforms, test_metrics'
114             + ' where config_platform = platform_id and config_metric = metric_id and platform_name in ($1, $2) order by config_id';
115         const db = TestServer.database();
116         submitReport(reports).then(function () {
117             return db.query(queryForConfig, [reports[0]['platform'], reports[2]['platform']]);
118         }).then(function (result) {
119             oldConfigs = result.rows;
120             assert.equal(oldConfigs.length, 2);
121             assert.equal(oldConfigs[0]['platform_name'], reports[0]['platform']);
122             assert.equal(oldConfigs[0]['metric_name'], 'FrameRate');
123             assert.equal(oldConfigs[0]['config_type'], 'baseline');
124             assert.equal(oldConfigs[1]['platform_name'], reports[2]['platform']);
125             assert.equal(oldConfigs[1]['metric_name'], 'FrameRate');
126             assert.equal(oldConfigs[1]['config_type'], 'current');
127         }).then(function () {
128             return TestServer.remoteAPI().postFormUrlencodedData('/admin/platforms.php',
129                 {'action': 'merge', 'id': oldConfigs[0]['platform_id'], 'destination': oldConfigs[1]['platform_id']});
130         }).then(function () {
131             return db.query(queryForConfig, [reports[0]['platform'], reports[2]['platform']]);
132         }).then(function (result) {
133             const newConfigs = result.rows;
134             assert.equal(newConfigs.length, 2);
135             assert.equal(newConfigs[0]['platform_name'], reports[2]['platform']);
136             assert.equal(newConfigs[0]['metric_name'], 'FrameRate');
137             assert.equal(newConfigs[0]['config_type'], 'baseline');
138             assert.equal(newConfigs[1]['platform_name'], reports[2]['platform']);
139             assert.equal(newConfigs[1]['metric_name'], 'FrameRate');
140             assert.equal(newConfigs[1]['config_type'], 'current');
141             done();
142         }).catch(done);
143     });
144
145 });