Dashboard cleanup: Remove globals g_buildersThatFailedToLoad and g_staleBuilders
[WebKit-https.git] / Tools / TestResultServer / static-dashboards / loader.js
index 0d7f7efb4530796803c45acd69c60ca1daaa608e..ed3c4f7898aeedb874dc8226f407fb04bc63e3fc 100644 (file)
@@ -64,6 +64,9 @@ loader.Loader = function()
         this._loadResultsFiles,
         this._loadExpectationsFiles,
     ];
         this._loadResultsFiles,
         this._loadExpectationsFiles,
     ];
+
+    this._buildersThatFailedToLoad = [];
+    this._staleBuilders = [];
 }
 
 loader.Loader.prototype = {
 }
 
 loader.Loader.prototype = {
@@ -75,7 +78,7 @@ loader.Loader.prototype = {
     {
         var loadingStep = this._loadingSteps.shift();
         if (!loadingStep) {
     {
         var loadingStep = this._loadingSteps.shift();
         if (!loadingStep) {
-            resourceLoadingComplete();
+            resourceLoadingComplete(this._getLoadingErrorMessages());
             return;
         }
         loadingStep.apply(this);
             return;
         }
         loadingStep.apply(this);
@@ -83,14 +86,13 @@ loader.Loader.prototype = {
     _loadBuildersList: function()
     {
         loadBuildersList(g_crossDashboardState.group, g_crossDashboardState.testType);
     _loadBuildersList: function()
     {
         loadBuildersList(g_crossDashboardState.group, g_crossDashboardState.testType);
-        initBuilders();
         this._loadNext();
     },
     _loadResultsFiles: function()
     {
         parseParameters();
 
         this._loadNext();
     },
     _loadResultsFiles: function()
     {
         parseParameters();
 
-        for (var builderName in g_builders)
+        for (var builderName in currentBuilders())
             this._loadResultsFileForBuilder(builderName);
     },
     _loadResultsFileForBuilder: function(builderName)
             this._loadResultsFileForBuilder(builderName);
     },
     _loadResultsFileForBuilder: function(builderName)
@@ -151,7 +153,7 @@ loader.Loader.prototype = {
                 continue;
 
             if ((Date.now() / 1000) - lastRunSeconds > ONE_DAY_SECONDS)
                 continue;
 
             if ((Date.now() / 1000) - lastRunSeconds > ONE_DAY_SECONDS)
-                g_staleBuilders.push(builderName);
+                this._staleBuilders.push(builderName);
 
             if (json_version >= 4)
                 builds[builderName][TESTS_KEY] = flattenTrie(builds[builderName][TESTS_KEY]);
 
             if (json_version >= 4)
                 builds[builderName][TESTS_KEY] = flattenTrie(builds[builderName][TESTS_KEY]);
@@ -160,35 +162,25 @@ loader.Loader.prototype = {
     },
     _handleResultsFileLoadError: function(builderName)
     {
     },
     _handleResultsFileLoadError: function(builderName)
     {
-        var error = 'Failed to load results file for ' + builderName + '.';
-
-        if (isLayoutTestResults()) {
-            console.error(error);
-            g_buildersThatFailedToLoad.push(builderName);
-        } else {
-            // Avoid to show error/warning messages for non-layout tests. We may be
-            // checking the builders that are not running the tests.
-            console.info('info:' + error);
-        }
+        console.error('Failed to load results file for ' + builderName + '.');
+
+        // FIXME: loader shouldn't depend on state defined in dashboard_base.js.
+        this._buildersThatFailedToLoad.push(builderName);
 
         // Remove this builder from builders, so we don't try to use the
         // data that isn't there.
 
         // Remove this builder from builders, so we don't try to use the
         // data that isn't there.
-        delete g_builders[builderName];
+        delete currentBuilders()[builderName];
 
         // Change the default builder name if it has been deleted.
 
         // Change the default builder name if it has been deleted.
-        if (g_defaultBuilderName == builderName) {
-            g_defaultBuilderName = null;
-            for (var availableBuilderName in g_builders) {
-                g_defaultBuilderName = availableBuilderName;
-                g_defaultDashboardSpecificStateValues.builder = availableBuilderName;
-                break;
-            }
-            if (!g_defaultBuilderName) {
+        if (g_defaultDashboardSpecificStateValues.builder == builderName) {
+            var defaultBuilderName = currentBuilderGroup().defaultBuilder();
+            g_defaultDashboardSpecificStateValues.builder = defaultBuilderName;
+            if (!defaultBuilderName) {
                 var error = 'No tests results found for ' + g_crossDashboardState.testType + '. Reload the page to try fetching it again.';
                 console.error(error);
                 addError(error);
             }
                 var error = 'No tests results found for ' + g_crossDashboardState.testType + '. Reload the page to try fetching it again.';
                 console.error(error);
                 addError(error);
             }
-        }
+       }
 
         // Proceed as if the resource had loaded.
         this._handleResourceLoad();
 
         // Proceed as if the resource had loaded.
         this._handleResourceLoad();
@@ -200,7 +192,7 @@ loader.Loader.prototype = {
     },
     _haveResultsFilesLoaded: function()
     {
     },
     _haveResultsFilesLoaded: function()
     {
-        for (var builder in g_builders) {
+        for (var builder in currentBuilders()) {
             if (!g_resultsByBuilder[builder])
                 return false;
         }
             if (!g_resultsByBuilder[builder])
                 return false;
         }
@@ -238,6 +230,17 @@ loader.Loader.prototype = {
                     partial(function(platformName, xhr) {
                         console.error('Could not load expectations file for ' + platformName);
                     }, platformWithExpectations));
                     partial(function(platformName, xhr) {
                         console.error('Could not load expectations file for ' + platformName);
                     }, platformWithExpectations));
+    },
+    _getLoadingErrorMessages: function()
+    {
+        var errorMsgs = '';
+        if (this._buildersThatFailedToLoad.length)
+            errorMsgs += 'ERROR: Failed to get data from ' + this._buildersThatFailedToLoad.toString() + '.<br>';
+
+        if (this._staleBuilders.length)
+            errorMsgs +='ERROR: Data from ' + this._staleBuilders.toString() + ' is more than 1 day stale.<br>';
+
+        return errorMsgs;
     }
 }
 
     }
 }