]> git.decadent.org.uk Git - dak.git/commitdiff
Do not use a separate session for timestamps during tests.
authorTorsten Werner <twerner@debian.org>
Mon, 31 Jan 2011 12:09:46 +0000 (13:09 +0100)
committerTorsten Werner <twerner@debian.org>
Mon, 31 Jan 2011 12:09:46 +0000 (13:09 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
tests/db_test.py
tests/dbtest_cruft.py
tests/dbtest_timestamps.py

index f91c15a82b783a7963a1ad51023b00b7eb767be2..dfd9c5386401ec5e7cd475a29d760d1d47dae39a 100644 (file)
@@ -171,6 +171,7 @@ class DBDakTestCase(DakTestCase):
 
         if 'source' in self.__dict__:
             return
+        install_date = self.now()
         self.setup_maintainers()
         self.setup_suites()
         self.setup_poolfiles()
@@ -178,22 +179,22 @@ class DBDakTestCase(DakTestCase):
         self.source['hello_2.2-2'] = DBSource(source = 'hello', version = '2.2-2', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['hello_2.2-2.dsc'], install_date = self.now())
+            poolfile = self.file['hello_2.2-2.dsc'], install_date = install_date)
         self.source['hello_2.2-2'].suites.append(self.suite['sid'])
         self.source['hello_2.2-1'] = DBSource(source = 'hello', version = '2.2-1', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['hello_2.2-1.dsc'], install_date = self.now())
+            poolfile = self.file['hello_2.2-1.dsc'], install_date = install_date)
         self.source['hello_2.2-1'].suites.append(self.suite['sid'])
         self.source['gnome-hello_3.0-1'] = DBSource(source = 'gnome-hello', \
             version = '3.0-1', maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['gnome-hello_3.0-1.dsc'], install_date = self.now())
+            poolfile = self.file['gnome-hello_3.0-1.dsc'], install_date = install_date)
         self.source['gnome-hello_3.0-1'].suites.append(self.suite['sid'])
         self.source['sl_3.03-16'] = DBSource(source = 'sl', version = '3.03-16', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['sl_3.03-16.dsc'], install_date = self.now())
+            poolfile = self.file['sl_3.03-16.dsc'], install_date = install_date)
         self.source['sl_3.03-16'].suites.append(self.suite['squeeze'])
         self.source['sl_3.03-16'].suites.append(self.suite['sid'])
         self.session.add_all(self.source.values())
@@ -240,13 +241,14 @@ class DBDakTestCase(DakTestCase):
         self.session = DBConn().session()
 
     def now(self):
-        "returns the current time at the db server"
+        """
+        Returns the current time at the db server. Please note the function
+        returns the same value as long as it is in the same transaction. You
+        should self.session.rollback() (or commit) if you rely on getting a
+        fresh timestamp.
+        """
 
-        # we fetch a fresh session each time to avoid caching
-        local_session = DBConn().session()
-        current_time = local_session.query(func.now()).scalar()
-        local_session.close()
-        return current_time
+        return self.session.query(func.now()).scalar()
 
     def classes_to_clean(self):
         """
index 27e321c77917dd76f86f73436f8bcdfb1f14aadf..1f9de72138ce0aade5d059478d8988c48603dc60 100755 (executable)
@@ -14,6 +14,7 @@ class CruftTestCase(DBDakTestCase):
 
     def setUp(self):
         super(CruftTestCase, self).setUp()
+        self.install_date = self.now()
         self.setup_binaries()
         # flush to make sure that the setup is correct
         self.session.flush()
@@ -28,7 +29,7 @@ class CruftTestCase(DBDakTestCase):
         self.source['sl_3.03-17'] = DBSource(source = 'sl', version = '3.03-17', \
             maintainer = self.maintainer['maintainer'], \
             changedby = self.maintainer['uploader'], \
-            poolfile = self.file['sl_3.03-17.dsc'], install_date = self.now())
+            poolfile = self.file['sl_3.03-17.dsc'], install_date = self.install_date)
         self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
         list = newer_version('squeeze', 'sid', self.session)
         self.assertEqual([('sl', '3.03-16', '3.03-17')], list)
index 8b35c63f804041f87e51e6e5a77ddc0f741f7d6d..8229e5dbdeb083ccce5ccc0121abf30a03c41d0e 100755 (executable)
@@ -20,6 +20,7 @@ class TimestampTestCase(DBDakTestCase):
 
     def test_timestamps(self):
         timestamp01 = self.now()
+        self.session.rollback()
         self.sleep()
         uid = Uid(uid = 'ftp-master@debian.org')
         self.session.add(uid)
@@ -28,6 +29,7 @@ class TimestampTestCase(DBDakTestCase):
         modified01 = uid.modified
         self.sleep()
         timestamp02 = self.now()
+        self.session.rollback()
         self.assertTrue(timestamp01 < created01)
         self.assertTrue(timestamp01 < modified01)
         self.assertTrue(created01 < timestamp02)
@@ -40,6 +42,7 @@ class TimestampTestCase(DBDakTestCase):
         self.assertEqual(created01, created02)
         self.assertTrue(modified01 < modified02)
         self.sleep()
+        self.session.rollback()
         timestamp03 = self.now()
         self.assertTrue(modified02 < timestamp03)