Changeset 195391 in webkit


Ignore:
Timestamp:
Jan 20, 2016, 4:20:33 PM (10 years ago)
Author:
jmarcell@apple.com
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.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js

    r188814 r195391  
    269269    compareIterations: function(a, b)
    270270    {
     271        result = this.compareIterationsByRevisions(a, b);
     272        if (result)
     273            return result;
     274
     275        // A loaded iteration may not have revision numbers if it failed early, before svn steps finished.
     276        result = b.loaded - a.loaded;
     277        if (result)
     278            return result;
     279
     280        return b.id - a.id;
     281    },
     282
     283    compareIterationsByRevisions: function(a, b)
     284    {
    271285        var sortedRepositories = Dashboard.sortedRepositories;
    272286        for (var i = 0; i < sortedRepositories.length; ++i) {
     
    277291        }
    278292
    279         // A loaded iteration may not have revision numbers if it failed early, before svn steps finished.
    280         result = b.loaded - a.loaded;
    281         if (result)
    282             return result;
    283 
    284         return b.id - a.id;
    285     },
    286 
    287     compareIterationsByRevisions: function(a, b)
    288     {
    289         var sortedRepositories = Dashboard.sortedRepositories;
    290         for (var i = 0; i < sortedRepositories.length; ++i) {
    291             var repositoryName = sortedRepositories[i].name;
    292             var result = b.revision[repositoryName] - a.revision[repositoryName];
    293             if (result)
    294                 return result;
    295         }
    296 
    297293        return 0;
    298294    },
     
    300296    sortIterations: function()
    301297    {
    302         this.iterations.sort(this.compareIterations);
     298        this.iterations.sort(this.compareIterations.bind(this));
    303299    }
    304300};
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js

    r195062 r195391  
    4343    equal(revisionsBehind, "1", "assert revisions behind");
    4444});
     45
     46module("BuildBotQueue", {
     47    setup: function() {
     48        this.queue = new MockBuildbotQueue();
     49        this.queue.branches = [{
     50            name: "trunk",
     51            repository: {
     52                name: "openSource",
     53            }
     54        }];
     55    }
     56});
     57
     58test("compareIterations by revisions", function()
     59{
     60    var finished = false;
     61    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     62    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     63    iteration1.revision = { "openSource": 33018 };
     64    iteration2.revision = { "openSource": 33019 };
     65    iteration1.loaded = true;
     66    iteration2.loaded = true;
     67    ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
     68    ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
     69    strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
     70});
     71
     72test("compareIterations by loaded (one revision missing)", function()
     73{
     74    var finished = false;
     75    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     76    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     77    iteration1.revision = {};
     78    iteration2.revision = { "openSource": 33019 };
     79    iteration1.loaded = false;
     80    iteration2.loaded = true;
     81    ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
     82    ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
     83});
     84
     85test("compareIterations by loaded (same revision)", function()
     86{
     87    var finished = false;
     88    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     89    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     90    iteration1.revision = { "openSource": 33019 };
     91    iteration2.revision = { "openSource": 33019 };
     92    iteration1.loaded = false;
     93    iteration2.loaded = true;
     94    ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
     95    ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
     96});
     97
     98test("compareIterations by id (revisions not specified)", function()
     99{
     100    var finished = false;
     101    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     102    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     103    iteration1.revision = {};
     104    iteration2.revision = {};
     105    iteration1.loaded = false;
     106    iteration2.loaded = false;
     107    ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
     108    ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
     109    strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
     110});
     111
     112test("compareIterations by id (same revision)", function()
     113{
     114    var finished = false;
     115    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     116    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     117    iteration1.revision = { "openSource": 33019 };
     118    iteration2.revision = { "openSource": 33019 };
     119    iteration1.loaded = false;
     120    iteration2.loaded = false;
     121    ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
     122    ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
     123    strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
     124});
     125
     126test("compareIterationsByRevisions", function()
     127{
     128    var finished = false;
     129    var iteration1 = new BuildbotIteration(this.queue, 1, finished);
     130    var iteration2 = new BuildbotIteration(this.queue, 2, finished);
     131    iteration1.revision = { "openSource": 33018 };
     132    iteration2.revision = { "openSource": 33019 };
     133    iteration1.loaded = true;
     134    iteration2.loaded = false;
     135    ok(this.queue.compareIterationsByRevisions(iteration2, iteration1) < 0, "compareIterationsByRevisions: less than");
     136    ok(this.queue.compareIterationsByRevisions(iteration1, iteration2) > 0, "compareIterationsByRevisions: greater than");
     137    strictEqual(this.queue.compareIterationsByRevisions(iteration2, iteration2), 0, "compareIterationsByRevisions: equal");
     138});
  • trunk/Tools/ChangeLog

    r195359 r195391  
     12016-01-20  Jason Marcell  <jmarcell@apple.com>
     2
     3        Refactor compareIterations to remove duplicate code.
     4        https://bugs.webkit.org/show_bug.cgi?id=152913
     5
     6        Reviewed by Daniel Bates.
     7
     8        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotQueue.js:
     9        (BuildbotQueue.prototype.compareIterations): Refactored to remove duplicate code.
     10        (BuildbotQueue.prototype.sortIterations): Add binding to call to compareIterations.
     11        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/tests/tests.js: Added tests in order to ensure
     12        the same behavior before and after refactor.
     13
    1142016-01-20  Dana Burkart  <dburkart@apple.com>
    215
Note: See TracChangeset for help on using the changeset viewer.