Skip to content

Commit 63b5977

Browse files
committed
BUG23722871: Fix running unittests with mysqlx plugin
Unittests hang when running the entire test suite with MySQLx tests. Each of the mysqlx tests in mysqlx_crud attempts to drop the main schema `myconnpy` as a part of test tearDown method. This causes a database lock since there are other sessions open with `myconnpy` as the default database. Previous sessions need to be closed before attempting to drop the schema. But the Session.close API is included in release 2.2.1. As of now, we do nothing in the tear down method.
1 parent 771c70e commit 63b5977

File tree

8 files changed

+117
-50
lines changed

8 files changed

+117
-50
lines changed

examples/dates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def main(config):
8282
except (mysql.connector.errors.Error, TypeError) as exc:
8383
output.append("Failed inserting {0}\nError: {1}\n".format(
8484
data, exc))
85+
cursor.execute(stmt_drop)
8586
raise
8687

8788
# Read the names again and print them

examples/microseconds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def main(config):
9595
except:
9696
# Ignoring the fact that it was not there
9797
pass
98-
98+
99+
cursor.execute("DROP TABLE IF EXISTS relay_laps")
99100
cursor.close()
100101
cnx.close()
101102

tests/cext/test_cext_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def test_autocommit(self):
426426
cmy2.query("SELECT * FROM {0} WHERE c1 > 3".format(table))
427427
self.assertEqual([(4,), (5,), (6,)], fetch_rows(cmy2))
428428

429+
cmy1.query("DROP TABLE IF EXISTS {0}".format(table))
429430
cmy1.close()
430431
cmy2.close()
431432

@@ -768,3 +769,4 @@ def test_next_result(self):
768769
have_more = cmy.next_result()
769770

770771
self.assertEqual(exp, result)
772+
cmy.query("DROP TABLE IF EXISTS {0}".format(table))

tests/test_bugs.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def test_execute_return(self):
109109
self.assertEqual(6, cur.rowcount)
110110
res = cur.execute("UPDATE %s SET id = id + %%s" % tbl, (10,))
111111
self.assertEqual(8, cur.rowcount)
112+
113+
cur.execute("DROP TABLE IF EXISTS {0}".format(tbl))
112114
cur.close()
113115
self.cnx.close()
114116

@@ -657,6 +659,13 @@ class BugOra13395083(tests.MySQLConnectorTests):
657659
def setUp(self):
658660
self.table_name = 'BugOra13395083'
659661

662+
def tearDown(self):
663+
config = tests.get_mysql_config()
664+
cnx = connection.MySQLConnection(**config)
665+
cur = cnx.cursor()
666+
667+
cur.execute("DROP TABLE IF EXISTS {0}".format(self.table_name))
668+
660669
@cnx_config(time_zone="+00:00")
661670
@foreach_cnx()
662671
def test_time_zone(self):
@@ -856,6 +865,12 @@ def _setup(self):
856865
self.cnx.cmd_query("DROP TABLE IF EXISTS %s" % self.table)
857866
self.cnx.cmd_query("CREATE TABLE %s (id INT)" % self.table)
858867

868+
def tearDown(self):
869+
config = tests.get_mysql_config()
870+
self.cnx = connection.MySQLConnection(**config)
871+
872+
self.cnx.cmd_query("DROP TABLE IF EXISTS {0}".format(self.table))
873+
859874
@foreach_cnx(connection.MySQLConnection)
860875
def test_cmd_query(self):
861876
self._setup()
@@ -943,6 +958,12 @@ def _setup(self):
943958
"PRIMARY KEY (`id`,`c1`))" % (self.tbl))
944959
cur.execute(create)
945960

961+
def tearDown(self):
962+
config = tests.get_mysql_config()
963+
cnx = connection.MySQLConnection(**config)
964+
cur = cnx.cursor()
965+
cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
966+
946967
@foreach_cnx()
947968
def test_executemany(self):
948969
self._setup()
@@ -2110,6 +2131,10 @@ def setUp(self):
21102131
"PRIMARY KEY (`id`))" % (self.city_tbl))
21112132
self.cursor.execute(create)
21122133

2134+
def tearDown(self):
2135+
self.cursor.execute("DROP TABLE IF EXISTS {0}".format(self.city_tbl))
2136+
self.cursor.execute("DROP TABLE IF EXISTS {0}".format(self.emp_tbl))
2137+
21132138
def test_executemany(self):
21142139
stmt = "INSERT INTO {0} (id,name) VALUES (%s,%s)".format(
21152140
self.city_tbl)
@@ -2448,6 +2473,15 @@ def _setup(self):
24482473
cur.execute(create)
24492474
cnx.close()
24502475

2476+
def tearDown(self):
2477+
config = tests.get_mysql_config()
2478+
config['use_unicode'] = True
2479+
cnx = connection.MySQLConnection(**config)
2480+
cur = cnx.cursor()
2481+
2482+
cur.execute("DROP TABLE IF EXISTS {0}".format(self.table))
2483+
cur.execute("DROP TABLE IF EXISTS {0}".format(self.table_cp1251))
2484+
24512485
@cnx_config(use_unicode=True)
24522486
@foreach_cnx(connection.MySQLConnection)
24532487
def test_prepared_statement(self):
@@ -2653,7 +2687,6 @@ def setUp(self):
26532687
self.cnx.cmd_query(create)
26542688

26552689
def tearDown(self):
2656-
return
26572690
if self.cnx:
26582691
self.cnx.cmd_query("DROP TABLE IF EXISTS {0}".format(self.tbl))
26592692

tests/test_cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ def setUp(self):
13321332
'name VARCHAR(20), city VARCHAR(20))')
13331333

13341334
def tearDown(self):
1335+
self.cur.execute('DROP TABLE IF EXISTS MySQLCursorBufferedDictTests')
13351336
self.cur.close()
13361337
self.connection.close()
13371338

@@ -1406,6 +1407,9 @@ def setUp(self):
14061407
'id INT(10), name VARCHAR(20), city VARCHAR(20))')
14071408

14081409
def tearDown(self):
1410+
self.cur.execute('DROP TABLE IF EXISTS '
1411+
'MySQLCursorBufferedNamedTupleTests')
1412+
14091413
self.cur.close()
14101414
self.connection.close()
14111415

tests/test_mysql_datatypes.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,14 @@ def drop_tables(self, cnx):
8484
class TestsCursor(TestsDataTypes):
8585

8686
def setUp(self):
87-
pass
88-
#self.config = tests.get_mysql_config()
89-
#cnx = connection.MySQLConnection(**self.config)
90-
#self.drop_tables(cnx)
87+
self.config = tests.get_mysql_config()
88+
cnx = connection.MySQLConnection(**self.config)
89+
self.drop_tables(cnx)
9190

9291
def tearDown(self):
93-
pass
94-
#cnx = connection.MySQLConnection(**self.config)
95-
#self.drop_tables(cnx)
96-
#cnx.close()
92+
cnx = connection.MySQLConnection(**self.config)
93+
self.drop_tables(cnx)
94+
cnx.close()
9795

9896
@foreach_cnx()
9997
def test_numeric_int(self):

tests/test_mysqlx_connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ def test_get_default_schema(self):
124124
session.close()
125125

126126
def test_drop_schema(self):
127-
self.session.drop_schema(self.schema_name)
128-
schema = self.session.get_schema(self.schema_name)
127+
test_schema = 'mysql_xsession_test_drop_schema'
128+
schema = self.session.create_schema(test_schema)
129+
130+
self.session.drop_schema(test_schema)
129131
self.assertFalse(schema.exists_in_database())
130132

131133
def test_create_schema(self):
@@ -196,8 +198,10 @@ def test_get_default_schema(self):
196198
session.close()
197199

198200
def test_drop_schema(self):
199-
self.session.drop_schema(self.schema_name)
200-
schema = self.session.get_schema(self.schema_name)
201+
test_schema = 'mysql_nodesession_test_drop_schema'
202+
schema = self.session.create_schema(test_schema)
203+
204+
self.session.drop_schema(test_schema)
201205
self.assertFalse(schema.exists_in_database())
202206

203207
def test_create_schema(self):

0 commit comments

Comments
 (0)