mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-13 04:26:33 +03:00
Work around a race condition in async cancel test
This commit is contained in:
parent
e599da6308
commit
d23fe42873
|
@ -23,11 +23,13 @@
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
# License for more details.
|
# License for more details.
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import extras
|
from psycopg2 import extras
|
||||||
|
|
||||||
from testconfig import dsn
|
from testconfig import dsn
|
||||||
from testutils import ConnectingTestCase, unittest, skip_before_postgres
|
from testutils import ConnectingTestCase, unittest, skip_before_postgres, slow
|
||||||
|
|
||||||
from test_replication import ReplicationTestCase, skip_repl_if_green
|
from test_replication import ReplicationTestCase, skip_repl_if_green
|
||||||
from psycopg2.extras import LogicalReplicationConnection, StopReplication
|
from psycopg2.extras import LogicalReplicationConnection, StopReplication
|
||||||
|
@ -97,13 +99,15 @@ class CancelTests(ConnectingTestCase):
|
||||||
)''')
|
)''')
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
|
@slow
|
||||||
@skip_before_postgres(8, 2)
|
@skip_before_postgres(8, 2)
|
||||||
def test_async_cancel(self):
|
def test_async_cancel(self):
|
||||||
async_conn = psycopg2.connect(dsn, async=True)
|
async_conn = psycopg2.connect(dsn, async=True)
|
||||||
self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
|
self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
|
||||||
extras.wait_select(async_conn)
|
extras.wait_select(async_conn)
|
||||||
cur = async_conn.cursor()
|
cur = async_conn.cursor()
|
||||||
cur.execute("select pg_sleep(10000)")
|
cur.execute("select pg_sleep(10)")
|
||||||
|
time.sleep(1)
|
||||||
self.assertTrue(async_conn.isexecuting())
|
self.assertTrue(async_conn.isexecuting())
|
||||||
async_conn.cancel()
|
async_conn.cancel()
|
||||||
self.assertRaises(psycopg2.extensions.QueryCanceledError,
|
self.assertRaises(psycopg2.extensions.QueryCanceledError,
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
# License for more details.
|
# License for more details.
|
||||||
|
|
||||||
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
@ -86,13 +87,15 @@ class CancelTests(ConnectingTestCase):
|
||||||
|
|
||||||
self.assertEqual(errors, [])
|
self.assertEqual(errors, [])
|
||||||
|
|
||||||
|
@slow
|
||||||
@skip_before_postgres(8, 2)
|
@skip_before_postgres(8, 2)
|
||||||
def test_async_cancel(self):
|
def test_async_cancel(self):
|
||||||
async_conn = psycopg2.connect(dsn, async_=True)
|
async_conn = psycopg2.connect(dsn, async_=True)
|
||||||
self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
|
self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
|
||||||
extras.wait_select(async_conn)
|
extras.wait_select(async_conn)
|
||||||
cur = async_conn.cursor()
|
cur = async_conn.cursor()
|
||||||
cur.execute("select pg_sleep(2)")
|
cur.execute("select pg_sleep(10)")
|
||||||
|
time.sleep(1)
|
||||||
self.assertTrue(async_conn.isexecuting())
|
self.assertTrue(async_conn.isexecuting())
|
||||||
async_conn.cancel()
|
async_conn.cancel()
|
||||||
self.assertRaises(psycopg2.extensions.QueryCanceledError,
|
self.assertRaises(psycopg2.extensions.QueryCanceledError,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user