Skip to content

Commit 8d0bd10

Browse files
Associated commits don't immediately show up on an analysis task page
https://bugs.webkit.org/show_bug.cgi?id=155692 Reviewed by Darin Adler. The bug was caused by resolveCommits in AnalysisTask._constructAnalysisTasksFromRawData not being able to find the matching commit log if the commit log had been created by the charts which don't set the remote identifiers on each CommitLog objects. Fixed the bug by modifying /api/measurement-set to include the commit ID, and making CommitLog use the real database ID as its ID instead of a fake ID we create from repository and revision. Also added a bunch of Mocha unit tests for AnalysisTask.fetchAll. * public/api/measurement-set.php: (MeasurementSetFetcher::execute_query): Fetch commit_id. (MeasurementSetFetcher::format_run): Use pass-by-reference to avoid making a copy of the row. (MeasurementSetFetcher::parse_revisions_array): Include commit_id as the first item in the result. * public/v3/instrumentation.js: * public/v3/models/analysis-task.js: (AnalysisTask): Fixed a bug that _buildRequestCount and _finishedBuildRequestCount could be kept as strings and hasPendingRequests() could return a wrong result because it would perform string inequality instead of numerical inequality. (AnalysisTask.prototype.updateSingleton): Ditto. (AnalysisTask.prototype.dissociateCommit): (AnalysisTask._constructAnalysisTasksFromRawData): (AnalysisTask._constructAnalysisTasksFromRawData.resolveCommits): Use findById now that CommitLog objects all use the same id as the database id. * public/v3/models/commit-log.js: (CommitLog): (CommitLog.prototype.remoteId): Deleted since we no longer create a fake id for commit logs for measurement sets. (CommitLog.findByRemoteId): Deleted. (CommitLog.ensureSingleton): Deleted. (CommitLog.fetchBetweenRevisions): * public/v3/models/data-model.js: (DataModelObject.clearStaticMap): Added to aid unit testing. (DataModelObject.ensureNamedStaticMap): Fixed a typo. Each map is a dictionary, not an array. * public/v3/models/metric.js: * public/v3/models/platform.js: * public/v3/models/root-set.js: (RootSet): Updated per the interface change in CommitLog.ensureSingleton. (MeasurementRootSet): Updated per /api/measurement-set change. Use the first value as the id. * public/v3/models/test.js: * unit-tests/analysis-task-tests.js: Added. (sampleAnalysisTask): (measurementCluster): * unit-tests/checkconfig.js: Added some assertion message to help aid diagnosing the failure. * unit-tests/measurement-adaptor-tests.js: Updated the sample data per the API change in /api/measurement-set and also added assertions for commit log ids. * unit-tests/measurement-set-tests.js: (beforeEach): * unit-tests/resources: Added. * unit-tests/resources/mock-remote-api.js: Added. Extracted from measurement-set-tests.js to be used in analysis-task-tests.js. (assert.notReached.assert.notReached): (global.RemoteAPI.getJSON): (global.RemoteAPI.getJSONWithStatus): (beforeEach): * unit-tests/resources/v3-models.js: Added. Extracted from measurement-set-tests.js to be used in analysis-task-tests.js and added more imports as needed. (importFromV3): (beforeEach): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@198479 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 272243a commit 8d0bd10

16 files changed

+433
-88
lines changed

Websites/perf.webkit.org/ChangeLog

+67
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
2016-03-19 Ryosuke Niwa <[email protected]>
2+
3+
Associated commits don't immediately show up on an analysis task page
4+
https://bugs.webkit.org/show_bug.cgi?id=155692
5+
6+
Reviewed by Darin Adler.
7+
8+
The bug was caused by resolveCommits in AnalysisTask._constructAnalysisTasksFromRawData not being
9+
able to find the matching commit log if the commit log had been created by the charts which don't
10+
set the remote identifiers on each CommitLog objects.
11+
12+
Fixed the bug by modifying /api/measurement-set to include the commit ID, and making CommitLog
13+
use the real database ID as its ID instead of a fake ID we create from repository and revision.
14+
15+
Also added a bunch of Mocha unit tests for AnalysisTask.fetchAll.
16+
17+
* public/api/measurement-set.php:
18+
(MeasurementSetFetcher::execute_query): Fetch commit_id.
19+
(MeasurementSetFetcher::format_run): Use pass-by-reference to avoid making a copy of the row.
20+
(MeasurementSetFetcher::parse_revisions_array): Include commit_id as the first item in the result.
21+
* public/v3/instrumentation.js:
22+
* public/v3/models/analysis-task.js:
23+
(AnalysisTask): Fixed a bug that _buildRequestCount and _finishedBuildRequestCount could be kept
24+
as strings and hasPendingRequests() could return a wrong result because it would perform string
25+
inequality instead of numerical inequality.
26+
(AnalysisTask.prototype.updateSingleton): Ditto.
27+
(AnalysisTask.prototype.dissociateCommit):
28+
(AnalysisTask._constructAnalysisTasksFromRawData):
29+
(AnalysisTask._constructAnalysisTasksFromRawData.resolveCommits): Use findById now that CommitLog
30+
objects all use the same id as the database id.
31+
* public/v3/models/commit-log.js:
32+
(CommitLog):
33+
(CommitLog.prototype.remoteId): Deleted since we no longer create a fake id for commit logs for
34+
measurement sets.
35+
(CommitLog.findByRemoteId): Deleted.
36+
(CommitLog.ensureSingleton): Deleted.
37+
(CommitLog.fetchBetweenRevisions):
38+
39+
* public/v3/models/data-model.js:
40+
(DataModelObject.clearStaticMap): Added to aid unit testing.
41+
(DataModelObject.ensureNamedStaticMap): Fixed a typo. Each map is a dictionary, not an array.
42+
* public/v3/models/metric.js:
43+
* public/v3/models/platform.js:
44+
* public/v3/models/root-set.js:
45+
(RootSet): Updated per the interface change in CommitLog.ensureSingleton.
46+
(MeasurementRootSet): Updated per /api/measurement-set change. Use the first value as the id.
47+
* public/v3/models/test.js:
48+
* unit-tests/analysis-task-tests.js: Added.
49+
(sampleAnalysisTask):
50+
(measurementCluster):
51+
* unit-tests/checkconfig.js: Added some assertion message to help aid diagnosing the failure.
52+
* unit-tests/measurement-adaptor-tests.js: Updated the sample data per the API change in
53+
/api/measurement-set and also added assertions for commit log ids.
54+
* unit-tests/measurement-set-tests.js:
55+
(beforeEach):
56+
* unit-tests/resources: Added.
57+
* unit-tests/resources/mock-remote-api.js: Added. Extracted from measurement-set-tests.js to be
58+
used in analysis-task-tests.js.
59+
(assert.notReached.assert.notReached):
60+
(global.RemoteAPI.getJSON):
61+
(global.RemoteAPI.getJSONWithStatus):
62+
(beforeEach):
63+
* unit-tests/resources/v3-models.js: Added. Extracted from measurement-set-tests.js to be used in
64+
analysis-task-tests.js and added more imports as needed.
65+
(importFromV3):
66+
(beforeEach):
67+
168
2016-03-18 Ryosuke Niwa <[email protected]>
269

370
Build fix after r198464.

Websites/perf.webkit.org/public/api/measurement-set.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function fetch_next_cluster() {
165165
function execute_query($config_id) {
166166
return $this->db->query('
167167
SELECT test_runs.*, builds.*,
168-
array_agg((commit_repository, commit_revision, commit_time)) AS revisions,
168+
array_agg((commit_id, commit_repository, commit_revision, commit_time)) AS revisions,
169169
max(commit_time) AS revision_time, max(commit_order) AS revision_order
170170
FROM builds
171171
LEFT OUTER JOIN build_commits ON commit_build = build_id
@@ -180,7 +180,7 @@ static function format_map()
180180
'commitTime', 'build', 'buildTime', 'buildNumber', 'builder');
181181
}
182182

183-
private static function format_run($run, &$commit_time) {
183+
private static function format_run(&$run, &$commit_time) {
184184
$commit_time = Database::to_js_time($run['revision_time']);
185185
$build_time = Database::to_js_time($run['build_time']);
186186
if (!$commit_time)
@@ -200,16 +200,19 @@ private static function format_run($run, &$commit_time) {
200200
intval($run['build_builder']));
201201
}
202202

203-
private static function parse_revisions_array($postgres_array) {
204-
// e.g. {"(WebKit,131456,\"2012-10-16 14:53:00\")","(Chromium,162004,)"}
203+
private static function parse_revisions_array(&$postgres_array) {
204+
// e.g. {"(<commit-id>,<repository-id>,<revision>,\"2012-10-16 14:53:00\")","(<commit-id>,<repository-id>,<revision>,)"}
205205
$outer_array = json_decode('[' . trim($postgres_array, '{}') . ']');
206206
$revisions = array();
207207
foreach ($outer_array as $item) {
208208
$name_and_revision = explode(',', trim($item, '()'));
209209
if (!$name_and_revision[0])
210210
continue;
211-
$time = Database::to_js_time(trim($name_and_revision[2], '"'));
212-
array_push($revisions, array(intval(trim($name_and_revision[0], '"')), trim($name_and_revision[1], '"'), $time));
211+
$commit_id = intval(trim($name_and_revision[0], '"'));
212+
$repository_id = intval(trim($name_and_revision[1], '"'));
213+
$revision = trim($name_and_revision[2], '"');
214+
$time = Database::to_js_time(trim($name_and_revision[3], '"'));
215+
array_push($revisions, array($commit_id, $repository_id, $revision, $time));
213216
}
214217
return $revisions;
215218
}

Websites/perf.webkit.org/public/v3/instrumentation.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
class Instrumentation {
24

35
static startMeasuringTime(domain, label)
@@ -53,3 +55,6 @@ class Instrumentation {
5355
}
5456

5557
}
58+
59+
if (typeof module != 'undefined')
60+
module.exports.Instrumentation = Instrumentation;

Websites/perf.webkit.org/public/v3/models/analysis-task.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12

23
class AnalysisTask extends LabeledObject {
34
constructor(id, object)
@@ -22,8 +23,8 @@ class AnalysisTask extends LabeledObject {
2223
this._bugs = object.bugs || [];
2324
this._causes = object.causes || [];
2425
this._fixes = object.fixes || [];
25-
this._buildRequestCount = object.buildRequestCount;
26-
this._finishedBuildRequestCount = object.finishedBuildRequestCount;
26+
this._buildRequestCount = +object.buildRequestCount;
27+
this._finishedBuildRequestCount = +object.finishedBuildRequestCount;
2728
}
2829

2930
static findByPlatformAndMetric(platformId, metricId)
@@ -50,8 +51,8 @@ class AnalysisTask extends LabeledObject {
5051
this._bugs = object.bugs || [];
5152
this._causes = object.causes || [];
5253
this._fixes = object.fixes || [];
53-
this._buildRequestCount = object.buildRequestCount;
54-
this._finishedBuildRequestCount = object.finishedBuildRequestCount;
54+
this._buildRequestCount = +object.buildRequestCount;
55+
this._finishedBuildRequestCount = +object.finishedBuildRequestCount;
5556
}
5657

5758
hasResults() { return this._finishedBuildRequestCount; }
@@ -138,7 +139,7 @@ class AnalysisTask extends LabeledObject {
138139
var id = this.id();
139140
return PrivilegedAPI.sendRequest('associate-commit', {
140141
task: id,
141-
commit: commit.remoteId(),
142+
commit: commit.id(),
142143
}).then(function (data) {
143144
return AnalysisTask.cachedFetch('../api/analysis-tasks', {id: id}, true)
144145
.then(AnalysisTask._constructAnalysisTasksFromRawData.bind(AnalysisTask));
@@ -232,11 +233,11 @@ class AnalysisTask extends LabeledObject {
232233
rawData.repository = Repository.findById(rawData.repository);
233234
if (!rawData.repository)
234235
continue;
235-
CommitLog.ensureSingleton(rawData.repository, rawData);
236+
CommitLog.ensureSingleton(rawData.id, rawData);
236237
}
237238

238239
function resolveCommits(commits) {
239-
return commits.map(function (id) { return CommitLog.findByRemoteId(id); }).filter(function (commit) { return !!commit; });
240+
return commits.map(function (id) { return CommitLog.findById(id); }).filter(function (commit) { return !!commit; });
240241
}
241242

242243
var results = [];
@@ -266,3 +267,6 @@ class AnalysisTask extends LabeledObject {
266267
});
267268
}
268269
}
270+
271+
if (typeof module != 'undefined')
272+
module.exports.AnalysisTask = AnalysisTask;

Websites/perf.webkit.org/public/v3/models/commit-log.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,13 @@ class CommitLog extends DataModelObject {
55
{
66
super(id);
77
this._repository = rawData.repository;
8+
console.assert(this._repository instanceof Repository);
89
this._rawData = rawData;
910
this._remoteId = rawData.id;
1011
if (this._remoteId)
1112
this.ensureNamedStaticMap('remoteId')[this._remoteId] = this;
1213
}
1314

14-
// FIXME: All this non-sense should go away once measurement-set start returning real commit id.
15-
remoteId() { return this._remoteId; }
16-
static findByRemoteId(id)
17-
{
18-
var remoteIdMap = super.namedStaticMap('remoteId');
19-
return remoteIdMap ? remoteIdMap[id] : null;
20-
}
21-
22-
static ensureSingleton(repository, rawData)
23-
{
24-
var id = repository.id() + '-' + rawData['revision'];
25-
rawData.repository = repository;
26-
return super.ensureSingleton(id, rawData);
27-
}
28-
2915
updateSingleton(rawData)
3016
{
3117
super.updateSingleton(rawData);
@@ -99,7 +85,10 @@ class CommitLog extends DataModelObject {
9985

10086
var self = this;
10187
return RemoteAPI.getJSONWithStatus(url).then(function (data) {
102-
var commits = data['commits'].map(function (rawData) { return CommitLog.ensureSingleton(repository, rawData); });
88+
var commits = data['commits'].map(function (rawData) {
89+
rawData.repository = repository;
90+
return CommitLog.ensureSingleton(rawData.id, rawData);
91+
});
10392
self._cacheCommitLogs(repository, from, to, commits);
10493
return commits;
10594
});

Websites/perf.webkit.org/public/v3/models/data-model.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DataModelObject {
2020

2121
updateSingleton(object) { }
2222

23+
static clearStaticMap() { this[DataModelObject.StaticMapSymbol] = null; }
24+
2325
static namedStaticMap(name)
2426
{
2527
var staticMap = this[DataModelObject.StaticMapSymbol];
@@ -32,7 +34,7 @@ class DataModelObject {
3234
this[DataModelObject.StaticMapSymbol] = {};
3335
var staticMap = this[DataModelObject.StaticMapSymbol];
3436
if (!staticMap[name])
35-
staticMap[name] = [];
37+
staticMap[name] = {};
3638
return staticMap[name];
3739
}
3840

Websites/perf.webkit.org/public/v3/models/metric.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12

23
class Metric extends LabeledObject {
34
constructor(id, object)
@@ -86,3 +87,6 @@ class Metric extends LabeledObject {
8687
}
8788
};
8889
}
90+
91+
if (typeof module != 'undefined')
92+
module.exports.Metric = Metric;

Websites/perf.webkit.org/public/v3/models/platform.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12

23
class Platform extends LabeledObject {
34
constructor(id, object)
@@ -34,3 +35,6 @@ class Platform extends LabeledObject {
3435
return this._lastModifiedByMetric[metric.id()];
3536
}
3637
}
38+
39+
if (typeof module != 'undefined')
40+
module.exports.Platform = Platform;

Websites/perf.webkit.org/public/v3/models/root-set.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class RootSet extends DataModelObject {
1414

1515
for (var row of object.roots) {
1616
var repositoryId = row.repository;
17-
var repository = Repository.findById(repositoryId);
17+
row.repository = Repository.findById(repositoryId);
1818

1919
console.assert(!this._repositoryToCommitMap[repositoryId]);
20-
this._repositoryToCommitMap[repositoryId] = CommitLog.ensureSingleton(repository, row);
21-
this._repositories.push(repository);
20+
this._repositoryToCommitMap[repositoryId] = CommitLog.ensureSingleton(row.id, row);
21+
this._repositories.push(row.repository);
2222
}
2323
}
2424

@@ -74,12 +74,16 @@ class MeasurementRootSet extends RootSet {
7474
{
7575
super(id, null);
7676
for (var values of revisionList) {
77-
var repositoryId = values[0];
77+
// [<commit-id>, <repository-id>, <revision>, <time>]
78+
var commitId = values[0];
79+
var repositoryId = values[1];
80+
var revision = values[2];
81+
var time = values[3];
7882
var repository = Repository.findById(repositoryId);
7983
if (!repository)
8084
continue;
8185

82-
this._repositoryToCommitMap[repositoryId] = CommitLog.ensureSingleton(repository, {revision: values[1], time: values[2]});
86+
this._repositoryToCommitMap[repositoryId] = CommitLog.ensureSingleton(commitId, {repository: repository, revision: revision, time: time});
8387
this._repositories.push(repository);
8488
}
8589
}

Websites/perf.webkit.org/public/v3/models/test.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12

23
class Test extends LabeledObject {
34
constructor(id, object, isTopLevel)
@@ -42,3 +43,6 @@ class Test extends LabeledObject {
4243
addChildTest(test) { this._childTests.push(test); }
4344
addMetric(metric) { this._metrics.push(metric); }
4445
}
46+
47+
if (typeof module != 'undefined')
48+
module.exports.Test = Test;

0 commit comments

Comments
 (0)