Skip to content

Commit 332a249

Browse files
committed
Sped up tests
Pytest possibly has some bug in the fixture scoping when theres multiple sets of parameterisation Unrolling the test parameterisation for SHA meant less containers spun up and down.
1 parent 6532b0d commit 332a249

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def ensure_mysql_verison(request, mysql_tag):
228228

229229
@pytest.fixture(scope='session')
230230
def mysql_server(unused_port, docker, session_id, mysql_tag, request):
231+
print('\nSTARTUP CONTAINER - {0}\n'.format(mysql_tag))
232+
231233
if not request.config.option.no_pull:
232234
docker.pull('mysql:{}'.format(mysql_tag))
233235

@@ -342,5 +344,6 @@ def mysql_server(unused_port, docker, session_id, mysql_tag, request):
342344

343345
yield container
344346
finally:
347+
print('\nTEARDOWN CONTAINER - {0}\n'.format(mysql_tag))
345348
docker.kill(container=container['Id'])
346349
docker.remove_container(container['Id'])

tests/test_sha_connection.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,78 @@
44
import pytest
55

66

7+
# You could parameterise these tests with this, but then pytest
8+
# does some funky stuff and spins up and tears down containers
9+
# per function call. Remember it would be
10+
# mysql_versions * event_loops * 4 auth tests ~= 3*2*4 ~= 24 tests
11+
12+
# As the MySQL daemon restarts at least 3 times in the container
13+
# before it becomes stable, there's a sleep(10) so that's
14+
# around a 4min wait time.
15+
16+
# @pytest.mark.parametrize("user,password,plugin", [
17+
# ("nopass_sha256", None, 'sha256_password'),
18+
# ("user_sha256", 'pass_sha256', 'sha256_password'),
19+
# ("nopass_caching_sha2", None, 'caching_sha2_password'),
20+
# ("user_caching_sha2", 'pass_caching_sha2', 'caching_sha2_password'),
21+
# ])
22+
23+
24+
@pytest.mark.mysql_verison('8.0')
25+
@pytest.mark.run_loop
26+
async def test_sha256_nopw(mysql_server, loop):
27+
connection_data = copy.copy(mysql_server['conn_params'])
28+
connection_data['user'] = 'nopass_sha256'
29+
connection_data['password'] = None
30+
31+
async with create_pool(**connection_data,
32+
loop=loop) as pool:
33+
async with pool.get() as conn:
34+
# User doesnt have any permissions to look at DBs
35+
# But as 8.0 will default to caching_sha2_password
36+
assert conn._auth_plugin_used == 'sha256_password'
37+
38+
39+
@pytest.mark.mysql_verison('8.0')
40+
@pytest.mark.run_loop
41+
async def test_sha256_pw(mysql_server, loop):
42+
connection_data = copy.copy(mysql_server['conn_params'])
43+
connection_data['user'] = 'user_sha256'
44+
connection_data['password'] = 'pass_sha256'
45+
46+
async with create_pool(**connection_data,
47+
loop=loop) as pool:
48+
async with pool.get() as conn:
49+
# User doesnt have any permissions to look at DBs
50+
# But as 8.0 will default to caching_sha2_password
51+
assert conn._auth_plugin_used == 'sha256_password'
52+
53+
54+
@pytest.mark.mysql_verison('8.0')
55+
@pytest.mark.run_loop
56+
async def test_cached_sha256_nopw(mysql_server, loop):
57+
connection_data = copy.copy(mysql_server['conn_params'])
58+
connection_data['user'] = 'nopass_caching_sha2'
59+
connection_data['password'] = None
60+
61+
async with create_pool(**connection_data,
62+
loop=loop) as pool:
63+
async with pool.get() as conn:
64+
# User doesnt have any permissions to look at DBs
65+
# But as 8.0 will default to caching_sha2_password
66+
assert conn._auth_plugin_used == 'caching_sha2_password'
67+
68+
769
@pytest.mark.mysql_verison('8.0')
870
@pytest.mark.run_loop
9-
@pytest.mark.parametrize("user,password,plugin", [
10-
("nopass_sha256", None, 'sha256_password'),
11-
("user_sha256", 'pass_sha256', 'sha256_password'),
12-
("nopass_caching_sha2", None, 'caching_sha2_password'),
13-
("user_caching_sha2", 'pass_caching_sha2', 'caching_sha2_password'),
14-
])
15-
async def test_sha(mysql_server, loop, user, password, plugin):
71+
async def test_cached_sha256_pw(mysql_server, loop):
1672
connection_data = copy.copy(mysql_server['conn_params'])
17-
connection_data['user'] = user
18-
connection_data['password'] = password
73+
connection_data['user'] = 'user_caching_sha2'
74+
connection_data['password'] = 'pass_caching_sha2'
1975

2076
async with create_pool(**connection_data,
2177
loop=loop) as pool:
2278
async with pool.get() as conn:
2379
# User doesnt have any permissions to look at DBs
2480
# But as 8.0 will default to caching_sha2_password
25-
assert conn._auth_plugin_used == plugin
81+
assert conn._auth_plugin_used == 'caching_sha2_password'

0 commit comments

Comments
 (0)