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)") self.assertTrue(async_conn.isexecuting()) async_conn.cancel() self.assertRaises(extensions.QueryCanceledError, extras.wait_select, async_conn) cur.execute("select 1") extras.wait_select(async_conn) self.assertEqual(cur.fetchall(), [(1, )])
def set_stub_wait_callback(self, conn): stub = ConnectionStub(conn) extensions.set_wait_callback(lambda conn: extras.wait_select(stub)) return stub