Add support for fetching recent builds in Buildbot 0.9 format in BuildbotSyncer
authoraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Feb 2018 16:53:22 +0000 (16:53 +0000)
committeraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Feb 2018 16:53:22 +0000 (16:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179743

Reviewed by Ryosuke Niwa.

* tools/js/buildbot-syncer.js:
(BuildbotSyncer.prototype._pullRecentBuildsDeprecated): Renamed from _pullRecentBuilds. This method fetch
from Buildbot 0.8 server.
(BuildbotSyncer.prototype._pullRecentBuilds): Method to fetch recent builds from Buildbot 0.9 server.
(BuildbotSyncer.prototype.pathForRecentBuilds): URL for fetching recent builds from Buildbot 0.9 server.
(BuildbotSyncer.prototype.pathForBuildJSONDeprecated): Renamed from pathForBuildJSON.
* unit-tests/buildbot-syncer-tests.js:
(_pullRecentBuilds.it): unit-test - should not fetch recent builds when count is zero.
(_pullRecentBuilds.it): unit-test - should pull the right number of recent builds.
(_pullRecentBuilds.it): unit-test - should handle unexpected error while fetching recent builds.
(_pullRecentBuilds.it): unit-test - should create BuildbotBuildEntry after fetching recent builds.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228098 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/tools/js/buildbot-syncer.js
Websites/perf.webkit.org/unit-tests/buildbot-syncer-tests.js

index b58c370..4d50d60 100644 (file)
@@ -1,3 +1,22 @@
+2018-02-02  Aakash Jain  <aakash_jain@apple.com>
+
+        Add support for fetching recent builds in Buildbot 0.9 format in BuildbotSyncer
+        https://bugs.webkit.org/show_bug.cgi?id=179743
+
+        Reviewed by Ryosuke Niwa.
+
+        * tools/js/buildbot-syncer.js:
+        (BuildbotSyncer.prototype._pullRecentBuildsDeprecated): Renamed from _pullRecentBuilds. This method fetch
+        from Buildbot 0.8 server.
+        (BuildbotSyncer.prototype._pullRecentBuilds): Method to fetch recent builds from Buildbot 0.9 server.
+        (BuildbotSyncer.prototype.pathForRecentBuilds): URL for fetching recent builds from Buildbot 0.9 server.
+        (BuildbotSyncer.prototype.pathForBuildJSONDeprecated): Renamed from pathForBuildJSON.
+        * unit-tests/buildbot-syncer-tests.js:
+        (_pullRecentBuilds.it): unit-test - should not fetch recent builds when count is zero.
+        (_pullRecentBuilds.it): unit-test - should pull the right number of recent builds.
+        (_pullRecentBuilds.it): unit-test - should handle unexpected error while fetching recent builds.
+        (_pullRecentBuilds.it): unit-test - should create BuildbotBuildEntry after fetching recent builds.
+
 2018-02-01  Aakash Jain  <aakash_jain@apple.com>
 
         Create BuildbotBuildEntry in Buildbot syncer in Buildbot 0.9 format
index 33a2746..bcd8a05 100644 (file)
@@ -198,7 +198,7 @@ class BuildbotSyncer {
     {
         return this._remote.getJSON(this.pathForPendingBuildsJSONDeprecated()).then((content) => {
             let pendingEntries = content.map((entry) => new BuildbotBuildEntryDeprecated(this, entry));
-            return this._pullRecentBuilds(count).then((entries) => {
+            return this._pullRecentBuildsDeprecated(count).then((entries) => {
                 let entryByRequest = {};
 
                 for (let entry of pendingEntries)
@@ -219,7 +219,7 @@ class BuildbotSyncer {
         });
     }
 
-    _pullRecentBuilds(count)
+    _pullRecentBuildsDeprecated(count)
     {
         if (!count)
             return Promise.resolve([]);
@@ -228,7 +228,7 @@ class BuildbotSyncer {
         for (let i = 0; i < count; i++)
             selectedBuilds[i] = -i - 1;
 
-        return this._remote.getJSON(this.pathForBuildJSON(selectedBuilds)).then((content) => {
+        return this._remote.getJSON(this.pathForBuildJSONDeprecated(selectedBuilds)).then((content) => {
             const entries = [];
             for (let index of selectedBuilds) {
                 const entry = content[index];
@@ -239,12 +239,25 @@ class BuildbotSyncer {
         });
     }
 
+    _pullRecentBuilds(count)
+    {
+        if (!count)
+            return Promise.resolve([]);
+
+        return this._remote.getJSON(this.pathForRecentBuilds(count)).then((content) => {
+            if (!('builds' in content))
+                return [];
+            return content.builds.map((build) => new BuildbotBuildEntry(this, build));
+        });
+    }
+
     pathForPendingBuildsJSONDeprecated() { return `/json/builders/${escape(this._builderName)}/pendingBuilds`; }
     pathForPendingBuilds() { return `/api/v2/builders/${this._builderID}/buildrequests?complete=false&claimed=false`; }
-    pathForBuildJSON(selectedBuilds)
+    pathForBuildJSONDeprecated(selectedBuilds)
     {
         return `/json/builders/${escape(this._builderName)}/builds/?` + selectedBuilds.map((number) => 'select=' + number).join('&');
     }
+    pathForRecentBuilds(count) { return `/api/v2/builders/${this._builderID}/builds?limit=${count}&order=-number&property=*`; }
     pathForForceBuild() { return `/builders/${escape(this._builderName)}/force`; }
 
     url() { return this._remote.url(`/builders/${escape(this._builderName)}/`); }
index d648c86..6653271 100644 (file)
@@ -1352,6 +1352,64 @@ describe('BuildbotSyncer', () => {
         });
     });
 
+    describe('_pullRecentBuilds()', () => {
+        it('should not fetch recent builds when count is zero', async () => {
+            const syncer = BuildbotSyncer._loadConfig(MockRemoteAPI, sampleiOSConfig(), builderNameToIDMap())[1];
+            const promise = syncer._pullRecentBuilds(0);
+            assert.equal(requests.length, 0);
+            const content = await promise;
+            assert.deepEqual(content, []);
+        });
+
+        it('should pull the right number of recent builds', () => {
+            const syncer = BuildbotSyncer._loadConfig(MockRemoteAPI, sampleiOSConfig(), builderNameToIDMap())[1];
+            syncer._pullRecentBuilds(12);
+            assert.equal(requests.length, 1);
+            assert.equal(requests[0].url, '/api/v2/builders/102/builds?limit=12&order=-number&property=*');
+        });
+
+        it('should handle unexpected error while fetching recent builds', async () => {
+            const syncer = BuildbotSyncer._loadConfig(MockRemoteAPI, sampleiOSConfig(), builderNameToIDMap())[1];
+            const promise = syncer._pullRecentBuilds(2);
+            assert.equal(requests.length, 1);
+            assert.equal(requests[0].url, '/api/v2/builders/102/builds?limit=2&order=-number&property=*');
+            requests[0].resolve({'error': 'Unexpected error'});
+            const content = await promise;
+            assert.deepEqual(content, []);
+        });
+
+        it('should create BuildbotBuildEntry after fetching recent builds', async () => {
+            const syncer = BuildbotSyncer._loadConfig(MockRemoteAPI, sampleiOSConfig(), builderNameToIDMap())[1];
+            const promise = syncer._pullRecentBuilds(2);
+            assert.equal(requests.length, 1);
+            assert.equal(requests[0].url, '/api/v2/builders/102/builds?limit=2&order=-number&property=*');
+            requests[0].resolve({'builds': [sampleFinishedBuildData(), sampleInProgressBuildData()]});
+
+            const entries = await promise;
+            assert.deepEqual(entries.length, 2);
+
+            let entry = entries[0];
+            assert.ok(entry instanceof BuildbotBuildEntry);
+            assert.equal(entry.buildNumber(), 1755);
+            assert.equal(entry.workerName(), 'ABTest-iPad-0');
+            assert.equal(entry.buildRequestId(), 18935);
+            assert.ok(!entry.isPending());
+            assert.ok(!entry.isInProgress());
+            assert.ok(entry.hasFinished());
+            assert.equal(entry.url(), 'http://build.webkit.org/#/builders/102/builds/1755');
+
+            entry = entries[1];
+            assert.ok(entry instanceof BuildbotBuildEntry);
+            assert.equal(entry.buildNumber(), 614);
+            assert.equal(entry.slaveName(), 'ABTest-iPad-0');
+            assert.equal(entry.buildRequestId(), 16733);
+            assert.ok(!entry.isPending());
+            assert.ok(entry.isInProgress());
+            assert.ok(!entry.hasFinished());
+            assert.equal(entry.url(), 'http://build.webkit.org/#/builders/102/builds/614');
+        });
+    });
+
     describe('pullBuildbot', () => {
         it('should fetch pending builds from the right URL', () => {
             let syncer = BuildbotSyncer._loadConfig(MockRemoteAPI, sampleiOSConfig(), builderNameToIDMap())[1];