Fix whitespace, add basic tests for get_summary_builds.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 2 Aug 2014 18:11:18 +0000 (20:11 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 2 Aug 2014 18:11:18 +0000 (20:11 +0200)
buildfarm/__init__.py
buildfarm/build.py
buildfarm/tests/test_buildfarm.py
buildfarm/web/__init__.py

index ec0556ab19538f2f2b1305aa432b8f6345076532..52ac0859c7e453a1c709e9bc2368b9f13acc5570 100644 (file)
@@ -17,6 +17,7 @@
 #   along with this program; if not, write to the Free Software
 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+from buildfarm.build import BuildStatus
 from buildfarm.sqldb import distinct_builds, Cast, StormBuild, setup_schema, StormHostDatabase
 from buildfarm.tree import Tree
 from storm.database import create_database
@@ -144,17 +145,24 @@ class BuildFarm(object):
         return distinct_builds(result.order_by(Desc(StormBuild.upload_time)))
 
     def get_summary_builds(self):
-        """returns tree and status to the ViewSummaryPage class"""
+        """Return last build age, status for each tree/host/compiler.
+
+        :return: iterator over tree, status
+        """
         store = self._get_store()
-        return store.execute("""
-SELECT obd.tree, obd.status AS status_str 
+        return ((tree, BuildStatus.__deserialize__(status_str))
+                for (tree, status_str) in store.execute("""
+SELECT obd.tree, obd.status AS status_str
 FROM build obd
 INNER JOIN(
-       SELECT MAX(age) age, tree, host, compiler
-       FROM build
-       GROUP BY tree, host, compiler
-) ibd ON obd.age = ibd.age AND obd.tree = ibd.tree AND  obd.host = ibd.host AND obd.compiler = ibd.compiler;
-""")
+    SELECT MAX(age) age, tree, host, compiler
+    FROM build
+    GROUP BY tree, host, compiler
+) ibd ON obd.age = ibd.age AND
+         obd.tree = ibd.tree AND
+         obd.host = ibd.host AND
+         obd.compiler = ibd.compiler;
+"""))
 
     def get_tree_builds(self, tree):
         result = self._get_store().find(StormBuild,
index a064bfaf6984eeb600087bc889e371547dc3a231..1348a96c49df9d634fa258c558c067dd0b9e689a 100644 (file)
@@ -566,9 +566,7 @@ class BuildResultStore(object):
         os.link(build.basename+".log", new_basename+".log")
         if os.path.exists(build.basename+".err"):
             os.link(build.basename+".err", new_basename+".err")
-        # They are supposed to be in unicode only but since comparision for sumary page depends on them 
-        # the unicode conversion is done to avoid duplicates when running query in summary_builds
-        new_build = StormBuild(new_basename, unicode(build.tree), unicode(build.host), unicode(build.compiler), rev)
+        new_build = StormBuild(new_basename, build.tree, build.host, build.compiler, rev)
         new_build.checksum = build.log_checksum()
         new_build.upload_time = build.upload_time
         new_build.status_str = build.status().__serialize__()
index d78ed6869fb27c13eeab9aff29ac261aeb750211..9091bf88fbbf03cddb44569fab16099106d33286 100644 (file)
@@ -119,6 +119,25 @@ class BuildFarmTests(BuildFarmTestCase):
         self.assertEquals("12", builds[1].revision_details())
         self.assertEquals("other", builds[1].tree)
 
+    def test_get_summary_builds_empty(self):
+        self.assertEquals([], list(self.x.get_summary_builds()))
+
+    def test_get_summary_builds(self):
+        path = self.upload_mock_logfile(self.x.builds, "other", "myhost", "cc",
+            "BUILD COMMIT REVISION: 12\n", mtime=1200)
+        path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
+            "BUILD COMMIT REVISION: 13\n", mtime=1300)
+        path = self.upload_mock_logfile(self.x.builds, "trivial", "myhost", "cc",
+            "BUILD COMMIT REVISION: 42\n", mtime=4200)
+        builds = list(self.x.get_summary_builds())
+        self.assertEquals(2, len(builds))
+        self.assertEquals(4200, builds[0].upload_time)
+        self.assertEquals("42", builds[0].revision_details())
+        self.assertEquals("trivial", builds[0].tree)
+        self.assertEquals(1200, builds[1].upload_time)
+        self.assertEquals("12", builds[1].revision_details())
+        self.assertEquals("other", builds[1].tree)
+
     def test_get_host_builds_empty(self):
         self.assertEquals([], list(self.x.get_host_builds("myhost")))
 
index 92730a0b4e3f198a1b014ef7f622690b781bce14..0368022dbfde9f4f6e86996b4fa1e41c6f31f632 100755 (executable)
@@ -43,7 +43,6 @@ from buildfarm.build import (
     LogFileMissing,
     NoSuchBuildError,
     NoTestOutput,
-    BuildStatus,
     )
 
 import cgi
@@ -730,9 +729,8 @@ class ViewSummaryPage(BuildFarmPage):
 
         builds = self.buildfarm.get_summary_builds()
 
-        for tree, status_str in builds:
+        for tree, status in builds:
             host_count[tree]+=1
-            status = BuildStatus.__deserialize__(status_str)
 
             if status.failed:
                 broken_count[tree]+=1