summaryrefslogtreecommitdiff
path: root/tests/test_async.py
diff options
context:
space:
mode:
authorJan UrbaƄski <wulczer@wulczer.org>2010-04-10 18:51:13 +0200
committerFederico Di Gregorio <fog@initd.org>2010-04-14 09:56:44 +0200
commit4afc1baf35917e57563082ab4f6e341582920acf (patch)
tree809cc4aeaed5f979395e1dcaed5a195ff74c7f88 /tests/test_async.py
parenta90935930bac87d0147d753366b2ff1bd265f9f0 (diff)
downloadpsycopg2-4afc1baf35917e57563082ab4f6e341582920acf.tar.gz
Make polling a cursor that's not in an async query raise an exception.
If there is an asynchronous query, polling a cursor that did not initiate it will raise an exception. Polling while there is no asynchronous query underway still works, because the user needs to have a way to get asynchronous NOTIFYs.
Diffstat (limited to 'tests/test_async.py')
-rwxr-xr-xtests/test_async.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_async.py b/tests/test_async.py
index da084bd..6cb9149 100755
--- a/tests/test_async.py
+++ b/tests/test_async.py
@@ -299,7 +299,6 @@ class AsyncTests(unittest.TestCase):
self.assert_(not conn.issync())
conn.close()
-
def test_flush_on_write(self):
# a very large query requires a flush loop to be sent to the backend
curs = self.conn.cursor()
@@ -315,6 +314,34 @@ class AsyncTests(unittest.TestCase):
self.fail("sending a large query didn't trigger block on write.")
+ def test_sync_poll(self):
+ cur = self.sync_conn.cursor()
+ # polling a sync cursor works
+ cur.poll()
+
+ def test_async_poll_wrong_cursor(self):
+ cur1 = self.conn.cursor()
+ cur2 = self.conn.cursor()
+ cur1.execute("select 1")
+
+ # polling a cursor that's not currently executing is an error
+ self.assertRaises(psycopg2.ProgrammingError, cur2.poll)
+
+ self.wait_for_query(cur1)
+ self.assertEquals(cur1.fetchone()[0], 1)
+
+ def test_async_fetch_wrong_cursor(self):
+ cur1 = self.conn.cursor()
+ cur2 = self.conn.cursor()
+ cur1.execute("select 1")
+
+ self.wait_for_query(cur1)
+ self.assertFalse(self.conn.executing())
+ # fetching from a cursor with no results is an error
+ self.assertRaises(psycopg2.ProgrammingError, cur2.fetchone)
+ # fetching from the correct cursor works
+ self.assertEquals(cur1.fetchone()[0], 1)
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)