From: aakash_jain@apple.com Date: Mon, 5 Feb 2018 16:53:22 +0000 (+0000) Subject: Add support for fetching recent builds in Buildbot 0.9 format in BuildbotSyncer X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=7bb843824d709e07f2d586c3785e1cee9fff7126 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. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228098 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Websites/perf.webkit.org/ChangeLog b/Websites/perf.webkit.org/ChangeLog index b58c370..4d50d60 100644 --- a/Websites/perf.webkit.org/ChangeLog +++ b/Websites/perf.webkit.org/ChangeLog @@ -1,3 +1,22 @@ +2018-02-02 Aakash Jain + + 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 Create BuildbotBuildEntry in Buildbot syncer in Buildbot 0.9 format diff --git a/Websites/perf.webkit.org/tools/js/buildbot-syncer.js b/Websites/perf.webkit.org/tools/js/buildbot-syncer.js index 33a2746..bcd8a05 100644 --- a/Websites/perf.webkit.org/tools/js/buildbot-syncer.js +++ b/Websites/perf.webkit.org/tools/js/buildbot-syncer.js @@ -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)}/`); } diff --git a/Websites/perf.webkit.org/unit-tests/buildbot-syncer-tests.js b/Websites/perf.webkit.org/unit-tests/buildbot-syncer-tests.js index d648c86..6653271 100644 --- a/Websites/perf.webkit.org/unit-tests/buildbot-syncer-tests.js +++ b/Websites/perf.webkit.org/unit-tests/buildbot-syncer-tests.js @@ -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];