All the sync tests pass on CockroachDB

Added decorator to skip tests on crdb
This commit is contained in:
Daniele Varrazzo 2020-07-21 01:55:22 +01:00
parent 659910ee81
commit ee34198bf6
2 changed files with 23 additions and 5 deletions

View File

@ -34,7 +34,7 @@ import psycopg2.errors
from psycopg2 import extensions as ext
from .testutils import (ConnectingTestCase, StringIO, skip_before_postgres,
crdb_version, slow)
skip_if_crdb, crdb_version, slow)
class PollableStub(object):
@ -114,7 +114,6 @@ class AsyncTests(ConnectingTestCase):
self.wait(cur)
self.assertFalse(self.conn.isexecuting())
self.assertEquals(cur.fetchall()[0][0], '')
@slow
def test_async_after_async(self):
@ -355,6 +354,7 @@ class AsyncTests(ConnectingTestCase):
self.assertEquals(cur.fetchone()[0], 1)
@slow
@skip_if_crdb
def test_notify(self):
cur = self.conn.cursor()
sync_cur = self.sync_conn.cursor()
@ -399,11 +399,12 @@ class AsyncTests(ConnectingTestCase):
self.assertRaises(psycopg2.IntegrityError, self.wait, cur)
cur.execute("insert into table1 values (%s); "
"insert into table1 values (%s)", (2, 2))
# this should fail as well
# this should fail as well (Postgres behaviour)
self.assertRaises(psycopg2.IntegrityError, self.wait, cur)
# but this should work
cur.execute("insert into table1 values (%s)", (2, ))
self.wait(cur)
if crdb_version(self.sync_conn) is None:
cur.execute("insert into table1 values (%s)", (2, ))
self.wait(cur)
# and the cursor should be usable afterwards
cur.execute("insert into table1 values (%s)", (3, ))
self.wait(cur)
@ -431,6 +432,7 @@ class AsyncTests(ConnectingTestCase):
self.wait(cur2)
self.assertEquals(cur2.fetchone()[0], 1)
@skip_if_crdb
def test_notices(self):
del self.conn.notices[:]
cur = self.conn.cursor()
@ -455,6 +457,7 @@ class AsyncTests(ConnectingTestCase):
self.wait(self.conn)
self.assertEqual(cur.fetchone(), (42,))
@skip_if_crdb
def test_async_connection_error_message(self):
try:
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async_=True)
@ -472,6 +475,7 @@ class AsyncTests(ConnectingTestCase):
self.assertRaises(psycopg2.ProgrammingError, self.wait, self.conn)
@slow
@skip_if_crdb
@skip_before_postgres(9, 0)
def test_non_block_after_notification(self):
from select import select
@ -505,6 +509,7 @@ class AsyncTests(ConnectingTestCase):
def test_poll_noop(self):
self.conn.poll()
@skip_if_crdb
@skip_before_postgres(9, 0)
def test_poll_conn_for_notification(self):
with self.conn.cursor() as cur:

View File

@ -439,6 +439,19 @@ def crdb_version(conn, __crdb_version=[]):
return __crdb_version[0]
@decorate_all_tests
def skip_if_crdb(f):
"""Skip a test or test class if we are testing against CockroachDB."""
@wraps(f)
def skip_if_crdb_(self):
if crdb_version(self.connect()) is not None:
self.skipTest("not supported on CockroachDB")
return f(self)
return skip_if_crdb_
class py3_raises_typeerror(object):
def __enter__(self):
pass