<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198853] trunk/Websites/perf.webkit.org</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198853">198853</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-30 12:46:23 -0700 (Wed, 30 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>BuildRequest should have a method to fetch all in-progress and pending requests for a triggerable
https://bugs.webkit.org/show_bug.cgi?id=156008

Reviewed by Darin Adler.

Add a method to BuildRequest that fetches all pending and in-progress requests for a triggerable.

Now, new syncing scripts must be able to figure out the build slave the first build requests in
a given test group had used in order to schedule subsequent build requests in the test group.

For this purpose, /api/build-requests has been modified to return all build requests whose test
group had not finished yet. A test group is finished if all build requests in the test group had
finished (completed, failed, or canceled).

* public/include/build-requests-fetcher.php:
(BuildRequestFetcher::fetch_incomplete_requests_for_triggerable): Return all build requests in test
groups that have not been finished.
* public/v3/models/build-request.js:
(BuildRequest):
(BuildRequest.prototype.testGroupId): Added.
(BuildRequest.prototype.isPending): Renamed from hasPending to fix a bad grammar.
(BuildRequest.fetchForTriggerable): Added.
(BuildRequest.constructBuildRequestsFromData): Extracted from _createModelsFromFetchedTestGroups in
TestGroup.
* public/v3/models/manifest.js:
(Manifest.fetch): Use the full path from root so that it works in server tests.
* public/v3/models/test-group.js:
(TestGroup.hasPending):
(TestGroup._createModelsFromFetchedTestGroups):
* server-tests/api-build-requests-tests.js: Added tests to ensure all build requests for a test group
is present in the response returned by /api/build-requests iff any build request in the group had not
finished yet.
(.addMockData):
(.addAnotherMockTestGroup): Added.
* unit-tests/test-groups-tests.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebsitesperfwebkitorgChangeLog">trunk/Websites/perf.webkit.org/ChangeLog</a></li>
<li><a href="#trunkWebsitesperfwebkitorgpublicincludebuildrequestsfetcherphp">trunk/Websites/perf.webkit.org/public/include/build-requests-fetcher.php</a></li>
<li><a href="#trunkWebsitesperfwebkitorgpublicv3modelsbuildrequestjs">trunk/Websites/perf.webkit.org/public/v3/models/build-request.js</a></li>
<li><a href="#trunkWebsitesperfwebkitorgpublicv3modelsmanifestjs">trunk/Websites/perf.webkit.org/public/v3/models/manifest.js</a></li>
<li><a href="#trunkWebsitesperfwebkitorgpublicv3modelstestgroupjs">trunk/Websites/perf.webkit.org/public/v3/models/test-group.js</a></li>
<li><a href="#trunkWebsitesperfwebkitorgservertestsapibuildrequeststestsjs">trunk/Websites/perf.webkit.org/server-tests/api-build-requests-tests.js</a></li>
<li><a href="#trunkWebsitesperfwebkitorgunitteststestgroupstestsjs">trunk/Websites/perf.webkit.org/unit-tests/test-groups-tests.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebsitesperfwebkitorgChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/ChangeLog (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/ChangeLog        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/ChangeLog        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2016-03-30  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        BuildRequest should have a method to fetch all in-progress and pending requests for a triggerable
+        https://bugs.webkit.org/show_bug.cgi?id=156008
+
+        Reviewed by Darin Adler.
+
+        Add a method to BuildRequest that fetches all pending and in-progress requests for a triggerable.
+
+        Now, new syncing scripts must be able to figure out the build slave the first build requests in
+        a given test group had used in order to schedule subsequent build requests in the test group.
+
+        For this purpose, /api/build-requests has been modified to return all build requests whose test
+        group had not finished yet. A test group is finished if all build requests in the test group had
+        finished (completed, failed, or canceled).
+
+        * public/include/build-requests-fetcher.php:
+        (BuildRequestFetcher::fetch_incomplete_requests_for_triggerable): Return all build requests in test
+        groups that have not been finished.
+        * public/v3/models/build-request.js:
+        (BuildRequest):
+        (BuildRequest.prototype.testGroupId): Added.
+        (BuildRequest.prototype.isPending): Renamed from hasPending to fix a bad grammar.
+        (BuildRequest.fetchForTriggerable): Added.
+        (BuildRequest.constructBuildRequestsFromData): Extracted from _createModelsFromFetchedTestGroups in
+        TestGroup.
+        * public/v3/models/manifest.js:
+        (Manifest.fetch): Use the full path from root so that it works in server tests.
+        * public/v3/models/test-group.js:
+        (TestGroup.hasPending):
+        (TestGroup._createModelsFromFetchedTestGroups):
+        * server-tests/api-build-requests-tests.js: Added tests to ensure all build requests for a test group
+        is present in the response returned by /api/build-requests iff any build request in the group had not
+        finished yet.
+        (.addMockData):
+        (.addAnotherMockTestGroup): Added.
+        * unit-tests/test-groups-tests.js:
+
</ins><span class="cx"> 2016-03-29  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Make dependency injection in unit tests more explicit
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicincludebuildrequestsfetcherphp"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/public/include/build-requests-fetcher.php (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/include/build-requests-fetcher.php        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/public/include/build-requests-fetcher.php        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -27,8 +27,11 @@
</span><span class="cx"> 
</span><span class="cx">     function fetch_incomplete_requests_for_triggerable($triggerable_id) {
</span><span class="cx">         $this-&gt;rows = $this-&gt;db-&gt;query_and_fetch_all('SELECT * FROM build_requests
</span><del>-            WHERE request_triggerable = $1 AND request_status != \'completed\'
-            ORDER BY request_created_at, request_group, request_order', array($triggerable_id));
</del><ins>+            WHERE request_triggerable = $1 AND request_group
+                IN (SELECT testgroup_id FROM analysis_test_groups WHERE EXISTS
+                    (SELECT 1 FROM build_requests WHERE testgroup_id = request_group AND request_status
+                        IN (\'pending\', \'scheduled\', \'running\')))
+            ORDER BY request_group, request_order', array($triggerable_id));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     function fetch_request($request_id) {
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicv3modelsbuildrequestjs"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/public/v3/models/build-request.js (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/v3/models/build-request.js        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/public/v3/models/build-request.js        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -5,6 +5,7 @@
</span><span class="cx">     constructor(id, object)
</span><span class="cx">     {
</span><span class="cx">         super(id, object);
</span><ins>+        this._testGroupId = object.testGroupId;
</ins><span class="cx">         console.assert(!object.testGroup || object.testGroup instanceof TestGroup);
</span><span class="cx">         this._testGroup = object.testGroup;
</span><span class="cx">         if (this._testGroup)
</span><span class="lines">@@ -28,13 +29,14 @@
</span><span class="cx">         this._buildId = object.build;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    testGroupId() { return this._testGroupId; }
</ins><span class="cx">     testGroup() { return this._testGroup; }
</span><span class="cx">     order() { return this._order; }
</span><span class="cx">     rootSet() { return this._rootSet; }
</span><span class="cx"> 
</span><span class="cx">     hasFinished() { return this._status == 'failed' || this._status == 'completed' || this._status == 'canceled'; }
</span><span class="cx">     hasStarted() { return this._status != 'pending'; }
</span><del>-    hasPending() { return this._status == 'pending'; }
</del><ins>+    isPending() { return this._status == 'pending'; }
</ins><span class="cx">     statusLabel()
</span><span class="cx">     {
</span><span class="cx">         switch (this._status) {
</span><span class="lines">@@ -62,6 +64,36 @@
</span><span class="cx">         this._result = result;
</span><span class="cx">         this._testGroup.didSetResult(this);
</span><span class="cx">     }
</span><ins>+
+    static fetchForTriggerable(triggerable)
+    {
+        return RemoteAPI.getJSONWithStatus('/api/build-requests/' + triggerable).then(function (data) {
+            return BuildRequest.constructBuildRequestsFromData(data);
+        });
+    }
+
+    static constructBuildRequestsFromData(data)
+    {
+        var rootIdMap = {};
+        for (var root of data['roots']) {
+            rootIdMap[root.id] = root;
+            root.repository = Repository.findById(root.repository);
+        }
+
+        var rootSets = data['rootSets'].map(function (row) {
+            row.roots = row.roots.map(function (rootId) { return rootIdMap[rootId]; });
+            return RootSet.ensureSingleton(row.id, row);
+        });
+
+        return data['buildRequests'].map(function (rawData) {
+            rawData.platform = Platform.findById(rawData.platform);
+            rawData.test = Test.findById(rawData.test);
+            rawData.testGroupId = rawData.testGroup;
+            rawData.testGroup = TestGroup.findById(rawData.testGroup);
+            rawData.rootSet = RootSet.findById(rawData.rootSet);
+            return BuildRequest.ensureSingleton(rawData.id, rawData);
+        });
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> if (typeof module != 'undefined')
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicv3modelsmanifestjs"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/public/v3/models/manifest.js (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/v3/models/manifest.js        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/public/v3/models/manifest.js        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -4,8 +4,8 @@
</span><span class="cx"> 
</span><span class="cx">     static fetch()
</span><span class="cx">     {
</span><del>-        return RemoteAPI.getJSON('../data/manifest.json').catch(function () {
-            return RemoteAPI.getJSON('../api/manifest/');
</del><ins>+        return RemoteAPI.getJSON('/data/manifest.json').catch(function () {
+            return RemoteAPI.getJSON('/api/manifest/');
</ins><span class="cx">         }).then(this._didFetchManifest.bind(this));
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicv3modelstestgroupjs"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/public/v3/models/test-group.js (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/v3/models/test-group.js        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/public/v3/models/test-group.js        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -112,7 +112,7 @@
</span><span class="cx"> 
</span><span class="cx">     hasPending()
</span><span class="cx">     {
</span><del>-        return this._buildRequests.some(function (request) { return request.hasPending(); });
</del><ins>+        return this._buildRequests.some(function (request) { return request.isPending(); });
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     compareTestResults(rootSetA, rootSetB)
</span><span class="lines">@@ -222,23 +222,8 @@
</span><span class="cx">             return TestGroup.ensureSingleton(row.id, row);
</span><span class="cx">         });
</span><span class="cx"> 
</span><del>-        var rootIdMap = {};
-        for (var root of data['roots']) {
-            rootIdMap[root.id] = root;
-            root.repository = Repository.findById(root.repository);
-        }
</del><ins>+        BuildRequest.constructBuildRequestsFromData(data);
</ins><span class="cx"> 
</span><del>-        var rootSets = data['rootSets'].map(function (row) {
-            row.roots = row.roots.map(function (rootId) { return rootIdMap[rootId]; });
-            return RootSet.ensureSingleton(row.id, row);
-        });
-
-        var buildRequests = data['buildRequests'].map(function (rawData) {
-            rawData.testGroup = TestGroup.findById(rawData.testGroup);
-            rawData.rootSet = RootSet.findById(rawData.rootSet);
-            return BuildRequest.ensureSingleton(rawData.id, rawData);
-        });
-
</del><span class="cx">         return testGroups;
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgservertestsapibuildrequeststestsjs"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/server-tests/api-build-requests-tests.js (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/server-tests/api-build-requests-tests.js        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/server-tests/api-build-requests-tests.js        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -1,12 +1,28 @@
</span><span class="cx"> 'use strict';
</span><span class="cx"> 
</span><span class="cx"> let assert = require('assert');
</span><ins>+
+require('../tools/js/v3-models.js');
+
</ins><span class="cx"> let TestServer = require('./resources/test-server.js');
</span><span class="cx"> 
</span><span class="cx"> describe('/api/build-requests', function () {
</span><span class="cx">     this.timeout(10000);
</span><span class="cx">     TestServer.inject();
</span><span class="cx"> 
</span><ins>+    beforeEach(function () {
+        AnalysisTask._fetchAllPromise = null;
+        AnalysisTask.clearStaticMap();
+        BuildRequest.clearStaticMap();
+        CommitLog.clearStaticMap();
+        Metric.clearStaticMap();
+        Platform.clearStaticMap();
+        Repository.clearStaticMap();
+        RootSet.clearStaticMap();
+        Test.clearStaticMap();
+        TestGroup.clearStaticMap();
+    })
+
</ins><span class="cx">     it('should return &quot;TriggerableNotFound&quot; when the database is empty', function (done) {
</span><span class="cx">         TestServer.remoteAPI().getJSON('/api/build-requests/build-webkit').then(function (content) {
</span><span class="cx">             assert.equal(content['status'], 'TriggerableNotFound');
</span><span class="lines">@@ -29,18 +45,21 @@
</span><span class="cx">         }).catch(done);
</span><span class="cx">     });
</span><span class="cx"> 
</span><del>-    function addMockData(db)
</del><ins>+    function addMockData(db, statusList)
</ins><span class="cx">     {
</span><ins>+        if (!statusList)
+            statusList = ['pending', 'pending', 'pending', 'pending'];
</ins><span class="cx">         return Promise.all([
</span><span class="cx">             db.insert('build_triggerables', {id: 1, name: 'build-webkit'}),
</span><span class="cx">             db.insert('repositories', {id: 9, name: 'OS X'}),
</span><span class="cx">             db.insert('repositories', {id: 11, name: 'WebKit'}),
</span><span class="cx">             db.insert('commits', {id: 87832, repository: 9, revision: '10.11 15A284'}),
</span><del>-            db.insert('commits', {id: 93116, repository: 11, revision: '191622', time: new Date(1445945816878)}),
-            db.insert('commits', {id: 96336, repository: 11, revision: '192736', time: new Date(1448225325650)}),
</del><ins>+            db.insert('commits', {id: 93116, repository: 11, revision: '191622', time: (new Date(1445945816878)).toISOString()}),
+            db.insert('commits', {id: 96336, repository: 11, revision: '192736', time: (new Date(1448225325650)).toISOString()}),
</ins><span class="cx">             db.insert('platforms', {id: 65, name: 'some platform'}),
</span><span class="cx">             db.insert('tests', {id: 200, name: 'some test'}),
</span><span class="cx">             db.insert('test_metrics', {id: 300, test: 200, name: 'some metric'}),
</span><ins>+            db.insert('test_configurations', {id: 301, metric: 300, platform: 65, type: 'current'}),
</ins><span class="cx">             db.insert('root_sets', {id: 401}),
</span><span class="cx">             db.insert('roots', {set: 401, commit: 87832}),
</span><span class="cx">             db.insert('roots', {set: 401, commit: 93116}),
</span><span class="lines">@@ -49,13 +68,26 @@
</span><span class="cx">             db.insert('roots', {set: 402, commit: 96336}),
</span><span class="cx">             db.insert('analysis_tasks', {id: 500, platform: 65, metric: 300, name: 'some task'}),
</span><span class="cx">             db.insert('analysis_test_groups', {id: 600, task: 500, name: 'some test group'}),
</span><del>-            db.insert('build_requests', {id: 700, triggerable: 1, platform: 65, test: 200, group: 600, order: 0, root_set: 401}),
-            db.insert('build_requests', {id: 701, triggerable: 1, platform: 65, test: 200, group: 600, order: 1, root_set: 402}),
-            db.insert('build_requests', {id: 702, triggerable: 1, platform: 65, test: 200, group: 600, order: 2, root_set: 401}),
-            db.insert('build_requests', {id: 703, triggerable: 1, platform: 65, test: 200, group: 600, order: 3, root_set: 402}),
</del><ins>+            db.insert('build_requests', {id: 700, status: statusList[0], triggerable: 1, platform: 65, test: 200, group: 600, order: 0, root_set: 401}),
+            db.insert('build_requests', {id: 701, status: statusList[1], triggerable: 1, platform: 65, test: 200, group: 600, order: 1, root_set: 402}),
+            db.insert('build_requests', {id: 702, status: statusList[2], triggerable: 1, platform: 65, test: 200, group: 600, order: 2, root_set: 401}),
+            db.insert('build_requests', {id: 703, status: statusList[3], triggerable: 1, platform: 65, test: 200, group: 600, order: 3, root_set: 402}),
</ins><span class="cx">         ]);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    function addAnotherMockTestGroup(db, statusList)
+    {
+        if (!statusList)
+            statusList = ['pending', 'pending', 'pending', 'pending'];
+        return Promise.all([
+            db.insert('analysis_test_groups', {id: 599, task: 500, name: 'another test group'}),
+            db.insert('build_requests', {id: 713, status: statusList[3], triggerable: 1, platform: 65, test: 200, group: 599, order: 3, root_set: 402}),
+            db.insert('build_requests', {id: 710, status: statusList[0], triggerable: 1, platform: 65, test: 200, group: 599, order: 0, root_set: 401}),
+            db.insert('build_requests', {id: 712, status: statusList[2], triggerable: 1, platform: 65, test: 200, group: 599, order: 2, root_set: 401}),
+            db.insert('build_requests', {id: 711, status: statusList[1], triggerable: 1, platform: 65, test: 200, group: 599, order: 1, root_set: 402}),
+        ]);
+    }
+
</ins><span class="cx">     it('should return build requets associated with a given triggerable with appropriate roots and rootSets', function (done) {
</span><span class="cx">         let db = TestServer.database();
</span><span class="cx">         db.connect().then(function () {
</span><span class="lines">@@ -114,7 +146,7 @@
</span><span class="cx">         }).catch(done);
</span><span class="cx">     });
</span><span class="cx"> 
</span><del>-    it('should return support useLegacyIdResolution option', function (done) {
</del><ins>+    it('should support useLegacyIdResolution option', function (done) {
</ins><span class="cx">         let db = TestServer.database();
</span><span class="cx">         db.connect().then(function () {
</span><span class="cx">             return addMockData(db);
</span><span class="lines">@@ -172,4 +204,183 @@
</span><span class="cx">         }).catch(done);
</span><span class="cx">     });
</span><span class="cx"> 
</span><ins>+    it('should be fetchable by BuildRequest.fetchForTriggerable', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return addMockData(db);
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 4);
+
+            assert.equal(buildRequests[0].id(), 700);
+            assert.equal(buildRequests[0].order(), 0);
+            assert.ok(buildRequests[0].rootSet() instanceof RootSet);
+            assert.ok(!buildRequests[0].hasFinished());
+            assert.ok(!buildRequests[0].hasStarted());
+            assert.ok(buildRequests[0].isPending());
+            assert.equal(buildRequests[0].statusLabel(), 'Waiting to be scheduled');
+
+            assert.equal(buildRequests[1].id(), 701);
+            assert.equal(buildRequests[1].order(), 1);
+            assert.ok(buildRequests[1].rootSet() instanceof RootSet);
+            assert.ok(!buildRequests[1].hasFinished());
+            assert.ok(!buildRequests[1].hasStarted());
+            assert.ok(buildRequests[1].isPending());
+            assert.equal(buildRequests[1].statusLabel(), 'Waiting to be scheduled');
+
+            assert.equal(buildRequests[2].id(), 702);
+            assert.equal(buildRequests[2].order(), 2);
+            assert.ok(buildRequests[2].rootSet() instanceof RootSet);
+            assert.ok(!buildRequests[2].hasFinished());
+            assert.ok(!buildRequests[2].hasStarted());
+            assert.ok(buildRequests[2].isPending());
+            assert.equal(buildRequests[2].statusLabel(), 'Waiting to be scheduled');
+
+            assert.equal(buildRequests[3].id(), 703);
+            assert.equal(buildRequests[3].order(), 3);
+            assert.ok(buildRequests[3].rootSet() instanceof RootSet);
+            assert.ok(!buildRequests[3].hasFinished());
+            assert.ok(!buildRequests[3].hasStarted());
+            assert.ok(buildRequests[3].isPending());
+            assert.equal(buildRequests[3].statusLabel(), 'Waiting to be scheduled');
+
+            let osx = Repository.findById(9);
+            assert.equal(osx.name(), 'OS X');
+
+            let webkit = Repository.findById(11);
+            assert.equal(webkit.name(), 'WebKit');
+
+            let firstRootSet = buildRequests[0].rootSet();
+            assert.equal(buildRequests[2].rootSet(), firstRootSet);
+
+            let secondRootSet = buildRequests[1].rootSet();
+            assert.equal(buildRequests[3].rootSet(), secondRootSet);
+
+            assert.equal(firstRootSet.revisionForRepository(osx), '10.11 15A284');
+            assert.equal(firstRootSet.revisionForRepository(webkit), '191622');
+
+            assert.equal(secondRootSet.revisionForRepository(osx), '10.11 15A284');
+            assert.equal(secondRootSet.revisionForRepository(webkit), '192736');
+
+            let osxCommit = firstRootSet.commitForRepository(osx);
+            assert.equal(osxCommit.revision(), '10.11 15A284');
+            assert.equal(osxCommit, secondRootSet.commitForRepository(osx));
+
+            let firstWebKitCommit = firstRootSet.commitForRepository(webkit);
+            assert.equal(firstWebKitCommit.revision(), '191622');
+            assert.equal(+firstWebKitCommit.time(), 1445945816878);
+
+            let secondWebKitCommit = secondRootSet.commitForRepository(webkit);
+            assert.equal(secondWebKitCommit.revision(), '192736');
+            assert.equal(+secondWebKitCommit.time(), 1448225325650);
+
+            done();
+        }).catch(done);
+    });
+
+    it('should not include a build request if all requests in the same group had been completed', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return addMockData(db, ['completed', 'completed', 'completed', 'completed']);
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 0);
+            done();
+        }).catch(done);
+    });
+
+    it('should not include a build request if all requests in the same group had been failed or cancled', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return addMockData(db, ['failed', 'failed', 'canceled', 'canceled']);
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 0);
+            done();
+        }).catch(done);
+    });
+
+    it('should include all build requests of a test group if one of the reqeusts in the group had not been finished', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return addMockData(db, ['completed', 'completed', 'scheduled', 'pending']);
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 4);
+            assert.ok(buildRequests[0].hasFinished());
+            assert.ok(buildRequests[0].hasStarted());
+            assert.ok(!buildRequests[0].isPending());
+            assert.ok(buildRequests[1].hasFinished());
+            assert.ok(buildRequests[1].hasStarted());
+            assert.ok(!buildRequests[1].isPending());
+            assert.ok(!buildRequests[2].hasFinished());
+            assert.ok(buildRequests[2].hasStarted());
+            assert.ok(!buildRequests[2].isPending());
+            assert.ok(!buildRequests[3].hasFinished());
+            assert.ok(!buildRequests[3].hasStarted());
+            assert.ok(buildRequests[3].isPending());
+            done();
+        }).catch(done);
+    });
+
+    it('should include all build requests of a test group if one of the reqeusts in the group is still running', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return addMockData(db, ['completed', 'completed', 'completed', 'running']);
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 4);
+            assert.ok(buildRequests[0].hasFinished());
+            assert.ok(buildRequests[0].hasStarted());
+            assert.ok(!buildRequests[0].isPending());
+            assert.ok(buildRequests[1].hasFinished());
+            assert.ok(buildRequests[1].hasStarted());
+            assert.ok(!buildRequests[1].isPending());
+            assert.ok(buildRequests[2].hasFinished());
+            assert.ok(buildRequests[2].hasStarted());
+            assert.ok(!buildRequests[2].isPending());
+            assert.ok(!buildRequests[3].hasFinished());
+            assert.ok(buildRequests[3].hasStarted());
+            assert.ok(!buildRequests[3].isPending());
+            done();
+        }).catch(done);
+    });
+
+    it('should order build requests based on test group and order', function (done) {
+        let db = TestServer.database();
+        db.connect().then(function () {
+            return Promise.all([addMockData(db), addAnotherMockTestGroup(db)])
+        }).then(function () {
+            return Manifest.fetch();
+        }).then(function () {
+            return BuildRequest.fetchForTriggerable('build-webkit');
+        }).then(function (buildRequests) {
+            assert.equal(buildRequests.length, 8);
+            assert.equal(buildRequests[0].id(), 710);
+            assert.equal(buildRequests[0].testGroupId(), 599);
+            assert.equal(buildRequests[1].id(), 711);
+            assert.equal(buildRequests[1].testGroupId(), 599);
+            assert.equal(buildRequests[2].id(), 712);
+            assert.equal(buildRequests[2].testGroupId(), 599);
+            assert.equal(buildRequests[3].id(), 713);
+            assert.equal(buildRequests[3].testGroupId(), 599);
+            done();
+        }).catch(done);
+    });
+
</ins><span class="cx"> });
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgunitteststestgroupstestsjs"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/unit-tests/test-groups-tests.js (198852 => 198853)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/unit-tests/test-groups-tests.js        2016-03-30 19:42:59 UTC (rev 198852)
+++ trunk/Websites/perf.webkit.org/unit-tests/test-groups-tests.js        2016-03-30 19:46:23 UTC (rev 198853)
</span><span class="lines">@@ -139,7 +139,7 @@
</span><span class="cx">             assert.equal(buildRequests[0].order(), 0);
</span><span class="cx">             assert.ok(!buildRequests[0].hasFinished());
</span><span class="cx">             assert.ok(!buildRequests[0].hasStarted());
</span><del>-            assert.ok(buildRequests[0].hasPending());
</del><ins>+            assert.ok(buildRequests[0].isPending());
</ins><span class="cx">             assert.equal(buildRequests[0].statusLabel(), 'Waiting to be scheduled');
</span><span class="cx">             assert.equal(buildRequests[0].buildId(), null);
</span><span class="cx">             assert.equal(buildRequests[0].result(), null);
</span><span class="lines">@@ -148,7 +148,7 @@
</span><span class="cx">             assert.equal(buildRequests[1].order(), 1);
</span><span class="cx">             assert.ok(!buildRequests[1].hasFinished());
</span><span class="cx">             assert.ok(!buildRequests[1].hasStarted());
</span><del>-            assert.ok(buildRequests[1].hasPending());
</del><ins>+            assert.ok(buildRequests[1].isPending());
</ins><span class="cx">             assert.equal(buildRequests[1].statusLabel(), 'Waiting to be scheduled');
</span><span class="cx">             assert.equal(buildRequests[1].buildId(), null);
</span><span class="cx">             assert.equal(buildRequests[1].result(), null);
</span></span></pre>
</div>
</div>

</body>
</html>