Title: [195391] trunk/Tools
Revision
195391
Author
jmarc...@apple.com
Date
2016-01-20 16:20:33 -0800 (Wed, 20 Jan 2016)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js (195390 => 195391)


--- trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js	2016-01-20 23:40:44 UTC (rev 195390)
+++ trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js	2016-01-21 00:20:33 UTC (rev 195391)
@@ -268,13 +268,9 @@
 
     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 @@
 
     sortIterations: function()
     {
-        this.iterations.sort(this.compareIterations);
+        this.iterations.sort(this.compareIterations.bind(this));
     }
 };

Modified: trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js (195390 => 195391)


--- trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js	2016-01-20 23:40:44 UTC (rev 195390)
+++ trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js	2016-01-21 00:20:33 UTC (rev 195391)
@@ -42,3 +42,97 @@
     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

Modified: trunk/Tools/ChangeLog (195390 => 195391)


--- trunk/Tools/ChangeLog	2016-01-20 23:40:44 UTC (rev 195390)
+++ trunk/Tools/ChangeLog	2016-01-21 00:20:33 UTC (rev 195391)
@@ -1,3 +1,16 @@
+2016-01-20  Jason Marcell  <jmarc...@apple.com>
+
+        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  <dburk...@apple.com>
 
         Botwatcher's dashboard should show an 'X' when the build is broken
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to