diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-06 18:05:13 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-06 21:40:05 +0000 |
commit | d23fe4287305bad5451b128cb22cd45c0926c2a4 (patch) | |
tree | b7856cfa78feb02e7e3e288222f3aea02dec58e4 | |
parent | e599da6308b348fe843c533da97e3d0cc4215952 (diff) | |
download | psycopg2-d23fe4287305bad5451b128cb22cd45c0926c2a4.tar.gz |
Work around a race condition in async cancel test
-rwxr-xr-x | tests/test_async_keyword.py | 8 | ||||
-rwxr-xr-x | tests/test_cancel.py | 5 |
2 files changed, 10 insertions, 3 deletions
diff --git a/tests/test_async_keyword.py b/tests/test_async_keyword.py index 37a61db..67dbb03 100755 --- a/tests/test_async_keyword.py +++ b/tests/test_async_keyword.py @@ -23,11 +23,13 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. +import time + import psycopg2 from psycopg2 import extras 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 psycopg2.extras import LogicalReplicationConnection, StopReplication @@ -97,13 +99,15 @@ class CancelTests(ConnectingTestCase): )''') self.conn.commit() + @slow @skip_before_postgres(8, 2) def test_async_cancel(self): async_conn = psycopg2.connect(dsn, async=True) self.assertRaises(psycopg2.OperationalError, async_conn.cancel) extras.wait_select(async_conn) cur = async_conn.cursor() - cur.execute("select pg_sleep(10000)") + cur.execute("select pg_sleep(10)") + time.sleep(1) self.assertTrue(async_conn.isexecuting()) async_conn.cancel() self.assertRaises(psycopg2.extensions.QueryCanceledError, diff --git a/tests/test_cancel.py b/tests/test_cancel.py index f267d99..9b3261c 100755 --- a/tests/test_cancel.py +++ b/tests/test_cancel.py @@ -23,6 +23,7 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. +import time import threading import psycopg2 @@ -86,13 +87,15 @@ class CancelTests(ConnectingTestCase): self.assertEqual(errors, []) + @slow @skip_before_postgres(8, 2) def test_async_cancel(self): async_conn = psycopg2.connect(dsn, async_=True) self.assertRaises(psycopg2.OperationalError, async_conn.cancel) extras.wait_select(async_conn) cur = async_conn.cursor() - cur.execute("select pg_sleep(2)") + cur.execute("select pg_sleep(10)") + time.sleep(1) self.assertTrue(async_conn.isexecuting()) async_conn.cancel() self.assertRaises(psycopg2.extensions.QueryCanceledError, |