mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Added test to verify named cursor efficiency.
Iter shouldn't fetch one record at time.
This commit is contained in:
parent
9433a6879f
commit
8a1de1ec4e
|
@ -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__)
|
||||
|
|
Loading…
Reference in New Issue
Block a user