diff --git a/tests/test_cursor.py b/tests/test_cursor.py index dec0cd14..da61c592 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -22,6 +22,7 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. +import time import unittest import psycopg2 import psycopg2.extensions @@ -128,6 +129,19 @@ class CursorTests(unittest.TestCase): del curs self.assert_(w() is None) + def test_iter_named_cursor_efficient(self): + curs = self.conn.cursor('tmp') + # if these records are fetched in the same roundtrip their + # timestamp will not be influenced by the pause in Python world. + curs.execute("""select clock_timestamp() from generate_series(1,2)""") + i = iter(curs) + t1 = i.next()[0] + time.sleep(0.2) + t2 = i.next()[0] + self.assert_((t2 - t1).microseconds * 1e-6 < 0.1, + "named cursor records fetched in 2 roundtrips (delta: %s)" + % (t2 - t1)) + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__)