Fix tests.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 22 Nov 2010 02:15:21 +0000 (03:15 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 22 Nov 2010 02:15:21 +0000 (03:15 +0100)
buildfarm/data.py
buildfarm/sqldb.py
buildfarm/tests/__init__.py
buildfarm/tests/test_buildfarm.py
buildfarm/tests/test_data.py
import-and-analyse.py

index 5ae1286a69bedc7b2f46f798dfedde19325ef00b..bec96f0371ecc9bd01bf95ae51817707bb5f1ad3 100644 (file)
@@ -203,15 +203,12 @@ def build_status_from_logs(log, err):
 
 def revision_from_log(log):
     revid = None
-    timestamp = None
     for l in log:
         if l.startswith("BUILD COMMIT REVISION: "):
             revid = l.split(":", 1)[1].strip()
-        elif l.startswith("BUILD COMMIT TIME"):
-            timestamp = l.split(":", 1)[1].strip()
     if revid is None:
         raise MissingRevisionInfo()
-    return (revid, timestamp)
+    return revid
 
 
 class NoSuchBuildError(Exception):
@@ -294,14 +291,14 @@ class Build(object):
             f.close()
 
     def summary(self):
-        (revid, timestamp) = self.revision_details()
+        revid = self.revision_details()
         status = self.status()
         return BuildSummary(self.host, self.tree, self.compiler, revid, status)
 
     def revision_details(self):
         """get the revision of build
 
-        :return: Tuple with revision id and timestamp (if available)
+        :return: revision id
         """
         f = self.read_log()
         try:
@@ -384,7 +381,7 @@ class BuildResultStore(object):
             if build.revision:
                 rev = build.revision
             else:
-                rev, timestamp = build.revision_details()
+                rev = build.revision_details()
             self.get_build(build.tree, build.host, build.compiler, rev)
         except NoSuchBuildError:
             return False
@@ -427,7 +424,7 @@ class BuildResultStore(object):
         return ret
 
     def upload_build(self, build):
-        (rev, rev_timestamp) = build.revision_details()
+        rev = build.revision_details()
 
         new_basename = self.build_fname(build.tree, build.host, build.compiler, rev)
         try:
index 7dd1f830056c7041300e43ddfb8a5b040104e4b3..47c33d329ce8dcdb548ee6be6404bcd408b64720 100644 (file)
@@ -79,7 +79,7 @@ class StormBuild(Build):
         return BuildStatus.__deserialize__(self.status_str)
 
     def revision_details(self):
-        return (self.revision, None)
+        return self.revision
 
     def log_checksum(self):
         return self.checksum
@@ -221,7 +221,7 @@ class StormCachingBuildResultStore(BuildResultStore):
             assert build.host == existing_build.host
             assert build.compiler == existing_build.compiler
             return existing_build
-        rev, timestamp = build.revision_details()
+        rev = build.revision_details()
         super(StormCachingBuildResultStore, self).upload_build(build)
         new_basename = self.build_fname(build.tree, build.host, build.compiler, rev)
         new_build = StormBuild(new_basename, build.tree, build.host,
index b510dbbcbf77bed61d3e357f2b5ced40bd4f0957..3c40379007d60ee6bea454acb4d0f275ecaae352 100644 (file)
@@ -36,6 +36,7 @@ class BuildFarmTestCase(TestCase):
             err_path = self.create_mock_logfile(tree, host, compiler, kind="stderr", contents=stderr_contents, mtime=mtime)
         build = Build(log_path[:-4], tree, host, compiler)
         store.upload_build(build)
+        return log_path
 
     def create_mock_logfile(self, tree, host, compiler, rev=None,
             kind="stdout", contents="FOO", mtime=None):
index a988be3cdf7c273175344892374e2c2927271d49..e213f904c4aef49c2d2d34481b2c6075b9e7037e 100644 (file)
@@ -108,10 +108,10 @@ class BuildFarmTestBase(object):
         builds = list(self.x.get_last_builds())
         self.assertEquals(2, len(builds))
         self.assertEquals(4200, builds[0].upload_time)
-        self.assertEquals("42", builds[0].revision_details()[0])
+        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()[0])
+        self.assertEquals("12", builds[1].revision_details())
         self.assertEquals("other", builds[1].tree)
 
     def test_get_host_builds_empty(self):
@@ -128,8 +128,9 @@ class BuildFarmTestBase(object):
         self.assertEquals("master", tree.branch)
 
     def test_get_build_rev(self):
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12",
-            contents="This is what a log file looks like.")
+        path = self.upload_mock_logfile(self.x.builds, "tdb", "charis", "cc",
+            stdout_contents="This is what a log file looks like.\n"
+            "BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
         self.assertEquals("tdb", build.tree)
         self.assertEquals("charis", build.host)
index c507a8c9587c479cdb820b22b44813e9b800434b..fd39675d72090683d9ebe26754e795b5b1d8aff5 100755 (executable)
@@ -40,14 +40,17 @@ class BuildResultStoreTestBase(object):
             "%s/data/oldrevs/build.mytree.myhost.cc-123" % self.path)
 
     def test_build_remove(self):
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12")
+        path = self.upload_mock_logfile(self.x, "tdb", "charis", "cc", 
+                "BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
+        logname = build.basename + ".log"
         build.remove()
-        self.assertFalse(os.path.exists(path))
+        self.assertFalse(os.path.exists(logname))
         self.assertRaises(data.NoSuchBuildError, self.x.get_build, "tdb", "charis", "cc", "12")
 
     def test_build_repr(self):
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12")
+        path = self.upload_mock_logfile(self.x, "tdb", "charis", "cc", 
+            "BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
         self.assertEquals("<%s: revision 12 of tdb on charis using cc>" % build.__class__.__name__, repr(build))
 
@@ -55,56 +58,59 @@ class BuildResultStoreTestBase(object):
         self.assertRaises(data.NoSuchBuildError, self.x.get_build, "tdb",
             "charis", "cc", "12")
 
-    def test_build_age_ctime(self):
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12")
-        # Set mtime to something in the past
-        os.utime(path, (5, 5))
+    def test_build_upload_time(self):
+        path = self.upload_mock_logfile(self.x, "tdb", "charis", "cc", 
+                "BUILD COMMIT REVISION: 12\n", mtime=5)
         build = self.x.get_build("tdb", "charis", "cc", "12")
         self.assertEquals(5, build.upload_time)
 
     def test_read_log(self):
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12",
-            contents="This is what a log file looks like.")
+        path = self.upload_mock_logfile(self.x, "tdb", "charis", "cc", 
+            stdout_contents="This is what a log file looks like.\n"
+            "BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
-        self.assertEquals("This is what a log file looks like.", build.read_log().read())
+        self.assertEquals("This is what a log file looks like.\n"
+                          "BUILD COMMIT REVISION: 12\n",
+                          build.read_log().read())
 
     def test_read_err(self):
-        self.create_mock_logfile("tdb", "charis", "cc", "12")
-        path = self.create_mock_logfile("tdb", "charis", "cc", "12",
-            kind="stderr",
-            contents="This is what an stderr file looks like.")
+        self.upload_mock_logfile(self.x, "tdb", "charis", "cc",
+            stdout_contents="BUILD COMMIT REVISION: 12\n",
+            stderr_contents="This is what an stderr file looks like.")
         build = self.x.get_build("tdb", "charis", "cc", "12")
-        self.assertEquals("This is what an stderr file looks like.", build.read_err().read())
+        self.assertEquals("This is what an stderr file looks like.",
+                build.read_err().read())
 
     def test_read_err_nofile(self):
-        self.create_mock_logfile("tdb", "charis", "cc", "12")
+        self.upload_mock_logfile(self.x, "tdb", "charis", "cc",
+                stdout_contents="BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
         self.assertEquals("", build.read_err().read())
 
     def test_revision_details(self):
-        self.create_mock_logfile("tdb", "charis", "cc", "12", contents="""
+        self.upload_mock_logfile(self.x, "tdb", "charis", "cc", stdout_contents="""
 BUILD COMMIT REVISION: 43
 bla
 BUILD COMMIT TIME: 3 August 2010
 """)
-        build = self.x.get_build("tdb", "charis", "cc", "12")
-        (rev, timestamp) = build.revision_details()
+        build = self.x.get_build("tdb", "charis", "cc", "43")
+        rev = build.revision_details()
         self.assertIsInstance(rev, str)
-        self.assertIsInstance(timestamp, str)
-        self.assertEquals(("43", "3 August 2010"), (rev, timestamp))
+        self.assertEquals("43", rev)
 
     def test_revision_details_no_timestamp(self):
-        self.create_mock_logfile("tdb", "charis", "cc", rev="12", contents="""
+        self.upload_mock_logfile(self.x, "tdb", "charis", "cc", stdout_contents="""
 BUILD COMMIT REVISION: 43
 BUILD REVISION: 42
 BLA
 """)
-        build = self.x.get_build("tdb", "charis", "cc", "12")
-        self.assertEquals(("43", None), build.revision_details())
+        build = self.x.get_build("tdb", "charis", "cc", "43")
+        self.assertEquals("43", build.revision_details())
 
     def test_err_count(self):
-        self.create_mock_logfile("tdb", "charis", "cc", "12")
-        self.create_mock_logfile("tdb", "charis", "cc", "12", kind="stderr", contents="""error1
+        self.upload_mock_logfile(self.x, "tdb", "charis", "cc",
+            stdout_contents="BUILD COMMIT REVISION: 12\n",
+            stderr_contents="""error1
 error2
 error3""")
         build = self.x.get_build("tdb", "charis", "cc", "12")
index ee389dfeb3ec14b22d0d1951710c3e83eb7f2d7a..9e24ebe81ffc68fc5e71aee6a444f34302640a35 100755 (executable)
@@ -31,10 +31,10 @@ smtp.connect()
 def check_and_send_mails(tree, host, compiler, cur, old):
     t = buildfarm.trees[tree]
 
-    (cur_rev, cur_rev_timestamp) = cur.revision_details()
+    cur_rev = cur.revision_details()
     cur_status = cur.status()
 
-    (old_rev, old_rev_timestamp) = old.revision_details()
+    old_rev = old.revision_details()
     old_status = old.status()
 
     if not cur_status.regressed_since(old_status):
@@ -102,7 +102,7 @@ for build in buildfarm.get_new_builds():
             continue
 
     try:
-        (rev, rev_timestamp) = build.revision_details()
+        rev = build.revision_details()
     except data.MissingRevisionInfo:
         print "No revision info in %r, skipping" % build
         continue