From 6e101a4a72a338c5f5929edc9281233ee8b2282b Mon Sep 17 00:00:00 2001 From: "jmarcell@apple.com" Date: Thu, 21 Jan 2016 00:20:33 +0000 Subject: [PATCH] Refactor compareIterations to remove duplicate code. https://bugs.webkit.org/show_bug.cgi?id=152913 Reviewed by Daniel Bates. * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js: (BuildbotQueue.prototype.compareIterations): Refactored to remove duplicate code. (BuildbotQueue.prototype.sortIterations): Add binding to call to compareIterations. * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js: Added tests in order to ensure the same behavior before and after refactor. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195391 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- .../public_html/dashboard/Scripts/BuildbotQueue.js | 12 +-- .../public_html/dashboard/Scripts/tests/tests.js | 94 ++++++++++++++++++++++ Tools/ChangeLog | 13 +++ 3 files changed, 111 insertions(+), 8 deletions(-) diff --git a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js index e4a9951..77198d0 100644 --- a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js +++ b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js @@ -268,13 +268,9 @@ BuildbotQueue.prototype = { compareIterations: function(a, b) { - var sortedRepositories = Dashboard.sortedRepositories; - for (var i = 0; i < sortedRepositories.length; ++i) { - var repositoryName = sortedRepositories[i].name; - var result = b.revision[repositoryName] - a.revision[repositoryName]; - if (result) - return result; - } + result = this.compareIterationsByRevisions(a, b); + if (result) + return result; // A loaded iteration may not have revision numbers if it failed early, before svn steps finished. result = b.loaded - a.loaded; @@ -299,6 +295,6 @@ BuildbotQueue.prototype = { sortIterations: function() { - this.iterations.sort(this.compareIterations); + this.iterations.sort(this.compareIterations.bind(this)); } }; diff --git a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js index 1934008..4a68313 100644 --- a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js +++ b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js @@ -42,3 +42,97 @@ test("_appendPendingRevisionCount", function() var revisionsBehind = view.element.getElementsByClassName("message")[0].innerHTML.match(/.*(\d+) revision(|s) behind/)[1]; equal(revisionsBehind, "1", "assert revisions behind"); }); + +module("BuildBotQueue", { + setup: function() { + this.queue = new MockBuildbotQueue(); + this.queue.branches = [{ + name: "trunk", + repository: { + name: "openSource", + } + }]; + } +}); + +test("compareIterations by revisions", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = { "openSource": 33018 }; + iteration2.revision = { "openSource": 33019 }; + iteration1.loaded = true; + iteration2.loaded = true; + ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than"); + ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than"); + strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal"); +}); + +test("compareIterations by loaded (one revision missing)", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = {}; + iteration2.revision = { "openSource": 33019 }; + iteration1.loaded = false; + iteration2.loaded = true; + ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than"); + ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than"); +}); + +test("compareIterations by loaded (same revision)", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = { "openSource": 33019 }; + iteration2.revision = { "openSource": 33019 }; + iteration1.loaded = false; + iteration2.loaded = true; + ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than"); + ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than"); +}); + +test("compareIterations by id (revisions not specified)", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = {}; + iteration2.revision = {}; + iteration1.loaded = false; + iteration2.loaded = false; + ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than"); + ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than"); + strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal"); +}); + +test("compareIterations by id (same revision)", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = { "openSource": 33019 }; + iteration2.revision = { "openSource": 33019 }; + iteration1.loaded = false; + iteration2.loaded = false; + ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than"); + ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than"); + strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal"); +}); + +test("compareIterationsByRevisions", function() +{ + var finished = false; + var iteration1 = new BuildbotIteration(this.queue, 1, finished); + var iteration2 = new BuildbotIteration(this.queue, 2, finished); + iteration1.revision = { "openSource": 33018 }; + iteration2.revision = { "openSource": 33019 }; + iteration1.loaded = true; + iteration2.loaded = false; + ok(this.queue.compareIterationsByRevisions(iteration2, iteration1) < 0, "compareIterationsByRevisions: less than"); + ok(this.queue.compareIterationsByRevisions(iteration1, iteration2) > 0, "compareIterationsByRevisions: greater than"); + strictEqual(this.queue.compareIterationsByRevisions(iteration2, iteration2), 0, "compareIterationsByRevisions: equal"); +}); \ No newline at end of file diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 5c408fc..68f05c5 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,16 @@ +2016-01-20 Jason Marcell + + Refactor compareIterations to remove duplicate code. + https://bugs.webkit.org/show_bug.cgi?id=152913 + + Reviewed by Daniel Bates. + + * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js: + (BuildbotQueue.prototype.compareIterations): Refactored to remove duplicate code. + (BuildbotQueue.prototype.sortIterations): Add binding to call to compareIterations. + * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js: Added tests in order to ensure + the same behavior before and after refactor. + 2016-01-20 Dana Burkart Botwatcher's dashboard should show an 'X' when the build is broken -- 1.8.3.1