Move some inappropriate code out of Builder
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jun 2011 18:27:33 +0000 (18:27 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jun 2011 18:27:33 +0000 (18:27 +0000)
Fixes <http://webkit.org/b/63406> TestFailure page's Builder class has a bunch of code that
isn't really about a builder

Reviewed by Anders Carlsson.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Builder.js:
(Builder.prototype.getBuildNames): Renamed from _getBuildNames, since it now needs to be
called by other objects.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestHistoryAnalyzer.js:
Added. Code came from Builder.
(LayoutTestHistoryAnalyzer):
(LayoutTestHistoryAnalyzer.prototype.start):
(LayoutTestHistoryAnalyzer.prototype._incorporateBuildHistory):

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestResultsLoader.js:
Added. Code came from Builder.
(LayoutTestResultsLoader):
(LayoutTestResultsLoader.prototype.start):

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
(ViewController.prototype._displayBuilder): Changed to use LayoutTestHistoryAnalyzer.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html: Pull in new
scripts.

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

Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Builder.js
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestHistoryAnalyzer.js [new file with mode: 0644]
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestResultsLoader.js [new file with mode: 0644]
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js
Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html
Tools/ChangeLog

index 6234597..4253494 100644 (file)
@@ -146,54 +146,6 @@ Builder.prototype = {
         });
     },
 
-    /*
-     * Preiodically calls callback until all current failures have been explained. Callback is
-     * passed an object like the following:
-     * {
-     *     'r12347 (681)': {
-     *         'tooManyFailures': false,
-     *         'tests': {
-     *             'css1/basic/class_as_selector2.html': 'fail',
-     *         },
-     *     },
-     *     'r12346 (680)': {
-     *         'tooManyFailures': false,
-     *         'tests': {},
-     *     },
-     *     'r12345 (679)': {
-     *         'tooManyFailures': false,
-     *         'tests': {
-     *             'css1/basic/class_as_selector.html': 'crash',
-     *         },
-     *     },
-     * },
-     * Each build contains just the failures that a) are still occuring on the bots, and b) were new
-     * in that build.
-     */
-    startFetchingBuildHistory: function(callback) {
-        var cacheKey = '_startFetchingBuildHistory';
-        if (!(cacheKey in this._cache))
-            this._cache[cacheKey] = {};
-
-        var history = this._cache[cacheKey];
-
-        var self = this;
-        self._getBuildNames(function(buildNames) {
-            function inner(buildIndex) {
-                self._incorporateBuildHistory(buildNames, buildIndex, history, function(callAgain) {
-                    var nextIndex = buildIndex + 1;
-                    if (nextIndex >= buildNames.length)
-                        callAgain = false;
-                    callback(history, callAgain);
-                    if (!callAgain)
-                        return;
-                    setTimeout(function() { inner(nextIndex) }, 0);
-                });
-            }
-            inner(0);
-        });
-    },
-
     resultsDirectoryURL: function(buildName) {
         return this.buildbot.resultsDirectoryURL(this.name, buildName);
     },
@@ -217,7 +169,7 @@ Builder.prototype = {
         });
     },
 
-    _getBuildNames: function(callback) {
+    getBuildNames: function(callback) {
         var cacheKey = '_getBuildNames';
         if (cacheKey in this._cache) {
             callback(this._cache[cacheKey]);
@@ -240,117 +192,4 @@ Builder.prototype = {
             callback(buildNames);
         });
     },
-
-    _getFailingTests: function(buildName, callback, errorCallback) {
-        var cacheKey = this.name + '__getFailingTests_' + buildName;
-        if (PersistentCache.contains(cacheKey)) {
-            callback(PersistentCache.get(cacheKey));
-            return;
-        }
-
-        var tests = {};
-
-        var parsedBuildName = this.buildbot.parseBuildName(buildName);
-
-        // http://webkit.org/b/62380 was fixed in r89610.
-        var resultsHTMLSupportsTooManyFailuresInfo = parsedBuildName.revision >= 89610;
-
-        var self = this;
-
-        function fetchAndParseResultsHTMLAndCallCallback(callback, tooManyFailures) {
-            getResource(self.resultsPageURL(buildName), function(xhr) {
-                var root = document.createElement('html');
-                root.innerHTML = xhr.responseText;
-
-                if (resultsHTMLSupportsTooManyFailuresInfo)
-                    tooManyFailures = root.getElementsByClassName('stopped-running-early-message').length > 0;
-
-                function testsForResultTable(regex) {
-                    var paragraph = Array.prototype.findFirst.call(root.querySelectorAll('p'), function(paragraph) {
-                        return regex.test(paragraph.innerText);
-                    });
-                    if (!paragraph)
-                        return [];
-                    var table = paragraph.nextElementSibling;
-                    console.assert(table.nodeName === 'TABLE');
-                    return Array.prototype.map.call(table.querySelectorAll('td:first-child > a'), function(elem) {
-                        return elem.innerText;
-                    });
-                }
-
-                testsForResultTable(/did not match expected results/).forEach(function(name) {
-                    tests[name] = 'fail';
-                });
-                testsForResultTable(/timed out/).forEach(function(name) {
-                    tests[name] = 'timeout';
-                });
-                testsForResultTable(/tool to crash/).forEach(function(name) {
-                    tests[name] = 'crash';
-                });
-                testsForResultTable(/Web process to crash/).forEach(function(name) {
-                    tests[name] = 'webprocess crash';
-                });
-
-                PersistentCache.set(cacheKey, tests);
-                callback(tests, tooManyFailures);
-            },
-            function(xhr) {
-                // We failed to fetch results.html. run-webkit-tests must have aborted early.
-                PersistentCache.set(cacheKey, tests);
-                errorCallback(tests, tooManyFailures);
-            });
-        }
-
-        if (resultsHTMLSupportsTooManyFailuresInfo) {
-            fetchAndParseResultsHTMLAndCallCallback(callback, false);
-            return;
-        }
-
-        self.getNumberOfFailingTests(parsedBuildName.buildNumber, function(failingTestCount, tooManyFailures) {
-            if (failingTestCount < 0) {
-                // The number of failing tests couldn't be determined.
-                PersistentCache.set(cacheKey, tests);
-                errorCallback(tests, tooManyFailures);
-                return;
-            }
-
-            if (!failingTestCount) {
-                // All tests passed.
-                PersistentCache.set(cacheKey, tests);
-                callback(tests, tooManyFailures);
-                return;
-            }
-
-            // Find out which tests failed.
-            fetchAndParseResultsHTMLAndCallCallback(callback, tooManyFailures);
-        });
-    },
-
-    _incorporateBuildHistory: function(buildNames, buildIndex, history, callback) {
-        var previousBuildName = Object.keys(history).last();
-        var nextBuildName = buildNames[buildIndex];
-
-        this._getFailingTests(nextBuildName, function(tests, tooManyFailures) {
-            history[nextBuildName] = {
-                tooManyFailures: tooManyFailures,
-                tests: {},
-            };
-
-            for (var testName in tests) {
-                if (previousBuildName) {
-                    if (!(testName in history[previousBuildName].tests))
-                        continue;
-                    delete history[previousBuildName].tests[testName];
-                }
-                history[nextBuildName].tests[testName] = tests[testName];
-            }
-
-            callback(Object.keys(history[nextBuildName].tests).length);
-        },
-        function(tests) {
-            // Some tests failed, but we couldn't fetch results.html (perhaps because the test
-            // run aborted early for some reason). Just skip this build entirely.
-            callback(true);
-        });
-    },
 };
diff --git a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestHistoryAnalyzer.js b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestHistoryAnalyzer.js
new file mode 100644 (file)
index 0000000..642f819
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function LayoutTestHistoryAnalyzer(builder) {
+    this._builder = builder;
+    this._cache = {};
+    this._loader = new LayoutTestResultsLoader(builder);
+}
+
+LayoutTestHistoryAnalyzer.prototype = {
+    /*
+     * Preiodically calls callback until all current failures have been explained. Callback is
+     * passed an object like the following:
+     * {
+     *     'r12347 (681)': {
+     *         'tooManyFailures': false,
+     *         'tests': {
+     *             'css1/basic/class_as_selector2.html': 'fail',
+     *         },
+     *     },
+     *     'r12346 (680)': {
+     *         'tooManyFailures': false,
+     *         'tests': {},
+     *     },
+     *     'r12345 (679)': {
+     *         'tooManyFailures': false,
+     *         'tests': {
+     *             'css1/basic/class_as_selector.html': 'crash',
+     *         },
+     *     },
+     * },
+     * Each build contains just the failures that a) are still occuring on the bots, and b) were new
+     * in that build.
+     */
+    start: function(callback) {
+        var cacheKey = '_startFetchingBuildHistory';
+        if (!(cacheKey in this._cache))
+            this._cache[cacheKey] = {};
+
+        var history = this._cache[cacheKey];
+
+        var self = this;
+        self._builder.getBuildNames(function(buildNames) {
+            function inner(buildIndex) {
+                self._incorporateBuildHistory(buildNames, buildIndex, history, function(callAgain) {
+                    var nextIndex = buildIndex + 1;
+                    if (nextIndex >= buildNames.length)
+                        callAgain = false;
+                    callback(history, callAgain);
+                    if (!callAgain)
+                        return;
+                    setTimeout(function() { inner(nextIndex) }, 0);
+                });
+            }
+            inner(0);
+        });
+    },
+
+    _incorporateBuildHistory: function(buildNames, buildIndex, history, callback) {
+        var previousBuildName = Object.keys(history).last();
+        var nextBuildName = buildNames[buildIndex];
+
+        this._loader.start(nextBuildName, function(tests, tooManyFailures) {
+            history[nextBuildName] = {
+                tooManyFailures: tooManyFailures,
+                tests: {},
+            };
+
+            for (var testName in tests) {
+                if (previousBuildName) {
+                    if (!(testName in history[previousBuildName].tests))
+                        continue;
+                    delete history[previousBuildName].tests[testName];
+                }
+                history[nextBuildName].tests[testName] = tests[testName];
+            }
+
+            callback(Object.keys(history[nextBuildName].tests).length);
+        },
+        function(tests) {
+            // Some tests failed, but we couldn't fetch results.html (perhaps because the test
+            // run aborted early for some reason). Just skip this build entirely.
+            callback(true);
+        });
+    },
+};
diff --git a/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestResultsLoader.js b/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestResultsLoader.js
new file mode 100644 (file)
index 0000000..a30e8af
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function LayoutTestResultsLoader(builder) {
+    this._builder = builder;
+}
+
+LayoutTestResultsLoader.prototype = {
+    start: function(buildName, callback, errorCallback) {
+        var cacheKey = 'LayoutTestResultsLoader.' + this._builder.name + '.' + buildName;
+        if (PersistentCache.contains(cacheKey)) {
+            callback(PersistentCache.get(cacheKey));
+            return;
+        }
+
+        var tests = {};
+
+        var parsedBuildName = this._builder.buildbot.parseBuildName(buildName);
+
+        // http://webkit.org/b/62380 was fixed in r89610.
+        var resultsHTMLSupportsTooManyFailuresInfo = parsedBuildName.revision >= 89610;
+
+        var self = this;
+
+        function fetchAndParseResultsHTMLAndCallCallback(callback, tooManyFailures) {
+            getResource(self._builder.resultsPageURL(buildName), function(xhr) {
+                var root = document.createElement('html');
+                root.innerHTML = xhr.responseText;
+
+                if (resultsHTMLSupportsTooManyFailuresInfo)
+                    tooManyFailures = root.getElementsByClassName('stopped-running-early-message').length > 0;
+
+                function testsForResultTable(regex) {
+                    var paragraph = Array.prototype.findFirst.call(root.querySelectorAll('p'), function(paragraph) {
+                        return regex.test(paragraph.innerText);
+                    });
+                    if (!paragraph)
+                        return [];
+                    var table = paragraph.nextElementSibling;
+                    console.assert(table.nodeName === 'TABLE');
+                    return Array.prototype.map.call(table.querySelectorAll('td:first-child > a'), function(elem) {
+                        return elem.innerText;
+                    });
+                }
+
+                testsForResultTable(/did not match expected results/).forEach(function(name) {
+                    tests[name] = 'fail';
+                });
+                testsForResultTable(/timed out/).forEach(function(name) {
+                    tests[name] = 'timeout';
+                });
+                testsForResultTable(/tool to crash/).forEach(function(name) {
+                    tests[name] = 'crash';
+                });
+                testsForResultTable(/Web process to crash/).forEach(function(name) {
+                    tests[name] = 'webprocess crash';
+                });
+
+                PersistentCache.set(cacheKey, tests);
+                callback(tests, tooManyFailures);
+            },
+            function(xhr) {
+                // We failed to fetch results.html. run-webkit-tests must have aborted early.
+                PersistentCache.set(cacheKey, tests);
+                errorCallback(tests, tooManyFailures);
+            });
+        }
+
+        if (resultsHTMLSupportsTooManyFailuresInfo) {
+            fetchAndParseResultsHTMLAndCallCallback(callback, false);
+            return;
+        }
+
+        self._builder.getNumberOfFailingTests(parsedBuildName.buildNumber, function(failingTestCount, tooManyFailures) {
+            if (failingTestCount < 0) {
+                // The number of failing tests couldn't be determined.
+                PersistentCache.set(cacheKey, tests);
+                errorCallback(tests, tooManyFailures);
+                return;
+            }
+
+            if (!failingTestCount) {
+                // All tests passed.
+                PersistentCache.set(cacheKey, tests);
+                callback(tests, tooManyFailures);
+                return;
+            }
+
+            // Find out which tests failed.
+            fetchAndParseResultsHTMLAndCallCallback(callback, tooManyFailures);
+        });
+    },
+};
index f54010a..15b9fee 100644 (file)
@@ -48,7 +48,7 @@ ViewController.prototype = {
 
     _displayBuilder: function(builder) {
         var self = this;
-        builder.startFetchingBuildHistory(function(history, stillFetchingData) {
+        (new LayoutTestHistoryAnalyzer(builder)).start(function(history, stillFetchingData) {
             var list = document.createElement('ol');
             list.id = 'failure-history';
             Object.keys(history).forEach(function(buildName, buildIndex, buildNameArray) {
index 9f43cc4..eccbffa 100644 (file)
@@ -30,6 +30,8 @@ THE POSSIBILITY OF SUCH DAMAGE.
     <script src="Bugzilla.js"></script>
     <script src="Buildbot.js"></script>
     <script src="Builder.js"></script>
+    <script src="LayoutTestHistoryAnalyzer.js"></script>
+    <script src="LayoutTestResultsLoader.js"></script>
     <script src="PersistentCache.js"></script>
     <script src="Trac.js"></script>
     <script src="Utilities.js"></script>
index 637b945..026e50a 100644 (file)
@@ -1,3 +1,33 @@
+2011-06-26  Adam Roben  <aroben@apple.com>
+
+        Move some inappropriate code out of Builder
+
+        Fixes <http://webkit.org/b/63406> TestFailure page's Builder class has a bunch of code that
+        isn't really about a builder
+
+        Reviewed by Anders Carlsson.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Builder.js:
+        (Builder.prototype.getBuildNames): Renamed from _getBuildNames, since it now needs to be
+        called by other objects.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestHistoryAnalyzer.js:
+        Added. Code came from Builder.
+        (LayoutTestHistoryAnalyzer):
+        (LayoutTestHistoryAnalyzer.prototype.start):
+        (LayoutTestHistoryAnalyzer.prototype._incorporateBuildHistory):
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/LayoutTestResultsLoader.js:
+        Added. Code came from Builder.
+        (LayoutTestResultsLoader):
+        (LayoutTestResultsLoader.prototype.start):
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
+        (ViewController.prototype._displayBuilder): Changed to use LayoutTestHistoryAnalyzer.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html: Pull in new
+        scripts.
+
 2011-05-17  Nat Duca  <nduca@chromium.org>
 
         Reviewed by James Robinson.