Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start MySQL from GH actions, upgrade ubuntu, and remove python versions for tests #384

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/UnitTesting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ on:

jobs:
test:
# "setup-python" action doesn't provide python 3.4 binaries for ubuntu-latest.
# Sticking to Ubuntu 18.04 as recommended here:
# https://github.com/actions/setup-python/issues/185#issuecomment-768232756
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
env:
py27: 2.7
py34: 3.4
py35: 3.5
py36: 3.6
py37: 3.7
py38: 3.8
py39: 3.9
py310: '3.10'
py311: '3.11'
DB_DATABASE: test_db
DB_USER: root
DB_PASSWORD: root
strategy:
fail-fast: false
matrix:
python-version: [py27, py34, py35, py36, py37, py38, py39, py310, py311]
python-version: [py37, py38, py39, py310, py311]
testenv: [core, ext]
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Start MySQL
run: |
jj22ee marked this conversation as resolved.
Show resolved Hide resolved
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}

- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down
51 changes: 25 additions & 26 deletions tests/ext/pymysql/test_pymysql.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import pymysql

import pytest
import testing.mysqld

from aws_xray_sdk.core import patch
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.ext.pymysql import unpatch

MYSQL_USER = "root"
MYSQL_PASSWORD = "root"
MYSQL_HOST = "localhost"
MYSQL_PORT = 3306
MYSQL_DB_NAME = "test_db"

@pytest.fixture(scope='module', autouse=True)
def patch_module():
Expand All @@ -32,46 +36,41 @@ def construct_ctx():

def test_execute_dsn_kwargs():
q = 'SELECT 1'
with testing.mysqld.Mysqld() as mysqld:
dsn = mysqld.dsn()
conn = pymysql.connect(database=dsn['db'],
user=dsn['user'],
password='',
host=dsn['host'],
port=dsn['port'])
cur = conn.cursor()
cur.execute(q)
conn = pymysql.connect(database=MYSQL_DB_NAME,
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT)
cur = conn.cursor()
cur.execute(q)

subsegment = xray_recorder.current_segment().subsegments[-1]
assert subsegment.name == 'execute'
sql = subsegment.sql
assert sql['database_type'] == 'MySQL'
assert sql['user'] == dsn['user']
assert sql['user'] == MYSQL_USER
assert sql['driver_version'] == 'PyMySQL'
assert sql['database_version']


def test_execute_bad_query():
q = "SELECT blarg"
with testing.mysqld.Mysqld() as mysqld:
dsn = mysqld.dsn()
conn = pymysql.connect(database=dsn['db'],
user=dsn['user'],
password='',
host=dsn['host'],
port=dsn['port'])

cur = conn.cursor()
try:
cur.execute(q)
except Exception:
pass

conn = pymysql.connect(database=MYSQL_DB_NAME,
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT)
cur = conn.cursor()
try:
cur.execute(q)
except Exception:
pass

subsegment = xray_recorder.current_segment().subsegments[-1]
assert subsegment.name == "execute"
sql = subsegment.sql
assert sql['database_type'] == 'MySQL'
assert sql['user'] == dsn['user']
assert sql['user'] == MYSQL_USER
assert sql['driver_version'] == 'PyMySQL'
assert sql['database_version']

Expand Down