[LNT] r302019 - Don't crash on the profile/admin page

Kristof Beyls via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 05:34:26 PDT 2017


Author: kbeyls
Date: Wed May  3 07:34:25 2017
New Revision: 302019

URL: http://llvm.org/viewvc/llvm-project?rev=302019&view=rev
Log:
Don't crash on the profile/admin page

... when there are no profiles on the server.
Fixes PR32724.

Added:
    lnt/trunk/tests/server/ui/test_system_info.py
Modified:
    lnt/trunk/lnt/server/ui/profile_views.py

Modified: lnt/trunk/lnt/server/ui/profile_views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/profile_views.py?rev=302019&r1=302018&r2=302019&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/profile_views.py (original)
+++ lnt/trunk/lnt/server/ui/profile_views.py Wed May  3 07:34:25 2017
@@ -39,10 +39,13 @@ def profile_admin():
 
     # Calculate a histogram bucket size that shows ~20 bars on the screen
     num_buckets = 20
-    
-    range = max(a[0] for a in age) - min(a[0] for a in age)
+
+    if len(age) > 0:
+        range = max(a[0] for a in age) - min(a[0] for a in age)
+    else:
+        range = 0
     bucket_size = float(range) / float(num_buckets)
-    
+
     # Construct the histogram.
     hist = {}
     for x,y in age:

Added: lnt/trunk/tests/server/ui/test_system_info.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/test_system_info.py?rev=302019&view=auto
==============================================================================
--- lnt/trunk/tests/server/ui/test_system_info.py (added)
+++ lnt/trunk/tests/server/ui/test_system_info.py Wed May  3 07:34:25 2017
@@ -0,0 +1,39 @@
+# create temporary instance
+# RUN: rm -rf %t.instance
+# RUN: python %{shared_inputs}/create_temp_instance.py \
+# RUN:     %s %{shared_inputs}/SmallInstance \
+# RUN:     %t.instance %S/Inputs/V4Pages_extra_records.sql
+#
+# RUN: python %s %t.instance
+
+import unittest
+import logging
+import sys
+
+import lnt.server.db.migrate
+import lnt.server.ui.app
+
+from V4Pages import check_code
+from V4Pages import HTTP_OK
+logging.basicConfig(level=logging.DEBUG)
+
+
+class SystemInfoTester(unittest.TestCase):
+    """Test the system info views."""
+
+    def setUp(self):
+        """Bind to the LNT test instance."""
+        _, instance_path = sys.argv
+        app = lnt.server.ui.app.App.create_standalone(instance_path)
+        app.testing = True
+        app.config['WTF_CSRF_ENABLED'] = False
+        self.client = app.test_client()
+
+    def test_profile_view(self):
+        """Does the page load without crashing the server?
+        """
+        check_code(self.client, '/profile/admin', expected_code=HTTP_OK)
+
+
+if __name__ == '__main__':
+    unittest.main(argv=[sys.argv[0], ])




More information about the llvm-commits mailing list