[dak/master] Do not use a separate session for timestamps during tests.
Signed-off-by: Torsten Werner <twerner@debian.org>
---
tests/db_test.py | 22 ++++++++++++----------
tests/dbtest_cruft.py | 3 ++-
tests/dbtest_timestamps.py | 3 +++
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/tests/db_test.py b/tests/db_test.py
index f91c15a..dfd9c53 100644
--- a/tests/db_test.py
+++ b/tests/db_test.py
@@ -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):
"""
diff --git a/tests/dbtest_cruft.py b/tests/dbtest_cruft.py
index 27e321c..1f9de72 100755
--- a/tests/dbtest_cruft.py
+++ b/tests/dbtest_cruft.py
@@ -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)
diff --git a/tests/dbtest_timestamps.py b/tests/dbtest_timestamps.py
index 8b35c63..8229e5d 100755
--- a/tests/dbtest_timestamps.py
+++ b/tests/dbtest_timestamps.py
@@ -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)
--
1.5.6.5
Reply to: