Skip to content

Commit

Permalink
Sped up tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
terricain committed Jul 8, 2018
1 parent 6532b0d commit 332a249
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 10 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def ensure_mysql_verison(request, mysql_tag):

@pytest.fixture(scope='session')
def mysql_server(unused_port, docker, session_id, mysql_tag, request):
print('\nSTARTUP CONTAINER - {0}\n'.format(mysql_tag))

if not request.config.option.no_pull:
docker.pull('mysql:{}'.format(mysql_tag))

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

yield container
finally:
print('\nTEARDOWN CONTAINER - {0}\n'.format(mysql_tag))
docker.kill(container=container['Id'])
docker.remove_container(container['Id'])
76 changes: 66 additions & 10 deletions tests/test_sha_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,78 @@
import pytest


# You could parameterise these tests with this, but then pytest
# does some funky stuff and spins up and tears down containers
# per function call. Remember it would be
# mysql_versions * event_loops * 4 auth tests ~= 3*2*4 ~= 24 tests

# As the MySQL daemon restarts at least 3 times in the container
# before it becomes stable, there's a sleep(10) so that's
# around a 4min wait time.

# @pytest.mark.parametrize("user,password,plugin", [
# ("nopass_sha256", None, 'sha256_password'),
# ("user_sha256", 'pass_sha256', 'sha256_password'),
# ("nopass_caching_sha2", None, 'caching_sha2_password'),
# ("user_caching_sha2", 'pass_caching_sha2', 'caching_sha2_password'),
# ])


@pytest.mark.mysql_verison('8.0')
@pytest.mark.run_loop
async def test_sha256_nopw(mysql_server, loop):
connection_data = copy.copy(mysql_server['conn_params'])
connection_data['user'] = 'nopass_sha256'
connection_data['password'] = None

async with create_pool(**connection_data,
loop=loop) as pool:
async with pool.get() as conn:
# User doesnt have any permissions to look at DBs
# But as 8.0 will default to caching_sha2_password
assert conn._auth_plugin_used == 'sha256_password'


@pytest.mark.mysql_verison('8.0')
@pytest.mark.run_loop
async def test_sha256_pw(mysql_server, loop):
connection_data = copy.copy(mysql_server['conn_params'])
connection_data['user'] = 'user_sha256'
connection_data['password'] = 'pass_sha256'

async with create_pool(**connection_data,
loop=loop) as pool:
async with pool.get() as conn:
# User doesnt have any permissions to look at DBs
# But as 8.0 will default to caching_sha2_password
assert conn._auth_plugin_used == 'sha256_password'


@pytest.mark.mysql_verison('8.0')
@pytest.mark.run_loop
async def test_cached_sha256_nopw(mysql_server, loop):
connection_data = copy.copy(mysql_server['conn_params'])
connection_data['user'] = 'nopass_caching_sha2'
connection_data['password'] = None

async with create_pool(**connection_data,
loop=loop) as pool:
async with pool.get() as conn:
# User doesnt have any permissions to look at DBs
# But as 8.0 will default to caching_sha2_password
assert conn._auth_plugin_used == 'caching_sha2_password'


@pytest.mark.mysql_verison('8.0')
@pytest.mark.run_loop
@pytest.mark.parametrize("user,password,plugin", [
("nopass_sha256", None, 'sha256_password'),
("user_sha256", 'pass_sha256', 'sha256_password'),
("nopass_caching_sha2", None, 'caching_sha2_password'),
("user_caching_sha2", 'pass_caching_sha2', 'caching_sha2_password'),
])
async def test_sha(mysql_server, loop, user, password, plugin):
async def test_cached_sha256_pw(mysql_server, loop):
connection_data = copy.copy(mysql_server['conn_params'])
connection_data['user'] = user
connection_data['password'] = password
connection_data['user'] = 'user_caching_sha2'
connection_data['password'] = 'pass_caching_sha2'

async with create_pool(**connection_data,
loop=loop) as pool:
async with pool.get() as conn:
# User doesnt have any permissions to look at DBs
# But as 8.0 will default to caching_sha2_password
assert conn._auth_plugin_used == plugin
assert conn._auth_plugin_used == 'caching_sha2_password'

0 comments on commit 332a249

Please sign in to comment.