Skip to content

Add docker-compose for local test #32

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

Merged
merged 3 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 57 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.2'
services:
percona-5.7:
platform: linux/amd64
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3306:3306
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates
restart: always
networks:
- default

percona-5.7-ctl:
image: percona:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: pymysqlreplication_test
ports:
- 3307:3307
command: mysqld --log-bin=mysql-bin.log --server-id 1 --binlog-format=row --gtid_mode=on --enforce-gtid-consistency=on --log_slave_updates -P 3307

pymysqlreplication:
build:
context: .
dockerfile: test.Dockerfile
args:
BASE_IMAGE: python:3.11-alpine
MYSQL_5_7: percona-5.7
MYSQL_5_7_CTL: percona-5.7-ctl

command:
- /bin/sh
- -ce
- |
echo "wait mysql server"

while :
do
if mysql -h percona-5.7 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null && mysql -h percona-5.7-ctl --port=3307 --user=root --execute "USE pymysqlreplication_test;" 2>&1 >/dev/null; then
break
fi
done

echo "run pytest"
pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos"

working_dir: /pymysqlreplication
networks:
- default
depends_on:
- percona-5.7

networks:
default: {}
4 changes: 1 addition & 3 deletions pymysqlreplication/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def ignoredEvents(self):
return []

def setUp(self):

db = os.environ.get('DB')
# default
self.database = {
"host": "localhost",
"host": os.environ.get("MYSQL_5_7") or "localhost",
"user": "root",
"passwd": "",
"port": 3306,
Expand Down
4 changes: 4 additions & 0 deletions pymysqlreplication/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import os

import pymysql
import copy
import time
Expand Down Expand Up @@ -768,6 +770,8 @@ def setUp(self):
ctl_db = copy.copy(self.database)
ctl_db["db"] = None
ctl_db["port"] = 3307
if os.environ.get("MYSQL_5_7_CTL") is not None:
ctl_db["host"] = os.environ.get("MYSQL_5_7_CTL")
self.ctl_conn_control = pymysql.connect(**ctl_db)
self.ctl_conn_control.cursor().execute("DROP DATABASE IF EXISTS pymysqlreplication_test")
self.ctl_conn_control.cursor().execute("CREATE DATABASE pymysqlreplication_test")
Expand Down
16 changes: 16 additions & 0 deletions test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG BASE_IMAGE=${BASE_IMAGE:-python:3.11-alpine}
FROM ${BASE_IMAGE}

COPY pymysqlreplication pymysqlreplication
COPY README.md README.md
COPY setup.py setup.py
RUN apk add bind-tools
RUN apk add mysql-client
RUN pip install .
RUN pip install pytest

ARG MYSQL_5_7
ENV MYSQL_5_7 ${MYSQL_5_7}

ARG MYSQL_5_7_CTL
ENV MYSQL_5_7_CTL ${MYSQL_5_7_CTL}