Skip to content

Commit

Permalink
GitHub Actions: Add macOS cases.
Browse files Browse the repository at this point in the history
* Migrate macOS cases in Travis to GitHub Actions.

* Increase the expected time in the test to avoid the following random failures
  on macOS.

  ```
  1) Mysql2::Client#query threaded queries should be supported
     Failure/Error: expect(stop - start).to be_within(0.1).of(sleep_time)
       expected 0.632204999999999 to be within 0.1 of 0.5
     # ./spec/mysql2/client_spec.rb:711:in `block (3 levels) in <top (required)>'
  ```

  ```
  3) Mysql2::Client#query should run signal handlers while waiting for a response
     Failure/Error: expect(mark.fetch(:QUERY_END) - mark.fetch(:QUERY_START)).to be_within(0.1).of(query_time)
       expected 1.1042130000000157 to be within 0.1 of 1.0
     # ./spec/mysql2/client_spec.rb:632:in `block (3 levels) in <top (required)>'
  ```
  • Loading branch information
junaruga committed Feb 24, 2021
1 parent 88fddbc commit 0f50311
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 50 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ubuntu.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ubuntu
name: Build
on: [push, pull_request]
jobs:
build:
Expand Down Expand Up @@ -38,6 +38,12 @@ jobs:
# `service mysql restart` fails.
- {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true}
- {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true}
# db: the DB's brew package name in macOS case.
# Allow failure due to the following test failures.
# https://github.com/brianmario/mysql2/issues/965
- {os: macos-latest, ruby: 2.4, db: '[email protected]', allow-failure: true}
# Allow failure due to Mysql2::Error: Unknown system variable 'session_track_system_variables'.
- {os: macos-latest, ruby: 2.4, db: '[email protected]', allow-failure: true}
# On the fail-fast: true, it cancels all in-progress jobs
# if any matrix job fails unlike Travis fast_finish.
fail-fast: false
Expand Down
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,5 @@ matrix:
addons:
hosts:
- mysql2gem.example.com
- os: osx
rvm: 2.4
env: DB=mysql56
addons:
hosts:
- mysql2gem.example.com
fast_finish: true
allow_failures:
- os: osx
rvm: 2.4
env: DB=mysql56
82 changes: 44 additions & 38 deletions .travis_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

set -eux

CHANGED_PWD=false
# Change the password recreating the root user on mariadb < 10.2
# Change the password to be empty.
CHANGED_PASSWORD=false
# Change the password to be empty, recreating the root user on mariadb < 10.2
# where ALTER USER is not available.
# https://stackoverflow.com/questions/56052177/
CHANGED_PWD_BY_RECREATE=false
CHANGED_PASSWORD_BY_RECREATE=false

# Install the default used DB if DB is not set.
if [[ -n ${GITHUB_ACTION-} && -z ${DB-} ]]; then
if [[ -n ${GITHUB_ACTIONS-} && -z ${DB-} ]]; then
if command -v lsb_release > /dev/null; then
case "$(lsb_release -cs)" in
xenial | bionic)
sudo apt-get install -qq mysql-server-5.7 mysql-client-core-5.7 mysql-client-5.7
CHANGED_PWD=true
CHANGED_PASSWORD=true
;;
focal)
sudo apt-get install -qq mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
CHANGED_PWD=true
CHANGED_PASSWORD=true
;;
*)
;;
Expand All @@ -34,30 +35,30 @@ fi
# Install MySQL 5.7 if DB=mysql57
if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then
sudo bash .travis_mysql57.sh
CHANGED_PWD=true
CHANGED_PASSWORD=true
fi

# Install MySQL 8.0 if DB=mysql80
if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then
sudo bash .travis_mysql80.sh
CHANGED_PWD=true
CHANGED_PASSWORD=true
fi

# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.0 ]]; then
if [[ -n ${GITHUB_ACTION-} ]]; then
if [[ -n ${GITHUB_ACTIONS-} ]]; then
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.0 libmariadb2
CHANGED_PWD_BY_RECREATE=true
CHANGED_PASSWORD_BY_RECREATE=true
else
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
fi
fi

# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.1 ]]; then
if [[ -n ${GITHUB_ACTION-} ]]; then
if [[ -n ${GITHUB_ACTIONS-} ]]; then
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.1 libmariadb-dev
CHANGED_PWD_BY_RECREATE=true
CHANGED_PASSWORD_BY_RECREATE=true
else
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
fi
Expand All @@ -70,16 +71,28 @@ if [[ -n ${DB-} && x$DB =~ ^xmariadb10.2 ]]; then
fi

# Install MariaDB 10.3 if DB=mariadb10.3
if [[ -n ${GITHUB_ACTION-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
if [[ -n ${GITHUB_ACTIONS-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev
CHANGED_PWD=true
CHANGED_PASSWORD=true
fi

# Install MySQL if OS=darwin
# Install MySQL/MariaDB if OS=darwin
if [[ x$OSTYPE =~ ^xdarwin ]]; then
brew update
brew update > /dev/null

# Check available packages.
for KEYWORD in mysql mariadb; do
brew search "${KEYWORD}"
done

brew install "$DB" mariadb-connector-c
$(brew --prefix "$DB")/bin/mysql.server start
DB_PREFIX="$(brew --prefix "${DB}")"
export PATH="${DB_PREFIX}/bin:${PATH}"
export LDFLAGS="-L${DB_PREFIX}/lib"
export CPPFLAGS="-I${DB_PREFIX}/include"

mysql.server start
CHANGED_PASSWORD_BY_RECREATE=true
fi

# TODO: get SSL working on OS X in Travis
Expand All @@ -88,14 +101,12 @@ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
sudo service mysql restart
fi

# Print the MySQL version and create the test DB
if [[ x$OSTYPE =~ ^xdarwin ]]; then
$(brew --prefix "$DB")/bin/mysqld --version
$(brew --prefix "$DB")/bin/mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'
else
mysqld --version
mysqld --version

if [[ -n ${GITHUB_ACTION-} && -f /etc/mysql/debian.cnf ]]; then
MYSQL_OPTS=''
DB_SYS_USER=root
if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
if [[ -n ${GITHUB_ACTIONS-} && -f /etc/mysql/debian.cnf ]]; then
MYSQL_OPTS='--defaults-extra-file=/etc/mysql/debian.cnf'
# Install from packages in OS official packages.
if sudo grep -q debian-sys-maint /etc/mysql/debian.cnf; then
Expand All @@ -105,25 +116,20 @@ else
# xenial
DB_SYS_USER=root
fi
else
# Install from official mysql packages.
MYSQL_OPTS=''
DB_SYS_USER=root
fi
fi

if [ "${CHANGED_PWD}" = true ]; then
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
elif [ "${CHANGED_PWD_BY_RECREATE}" = true ]; then
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
if [ "${CHANGED_PASSWORD}" = true ]; then
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
elif [ "${CHANGED_PASSWORD_BY_RECREATE}" = true ]; then
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SQL
fi

# IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
fi

mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'
4 changes: 2 additions & 2 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def run_gc
end

# the query ran uninterrupted
expect(mark.fetch(:QUERY_END) - mark.fetch(:QUERY_START)).to be_within(0.1).of(query_time)
expect(mark.fetch(:QUERY_END) - mark.fetch(:QUERY_START)).to be_within(0.2).of(query_time)
# signals fired while the query was running
expect(mark.fetch(:USR1)).to be_between(mark.fetch(:QUERY_START), mark.fetch(:QUERY_END))
end
Expand Down Expand Up @@ -708,7 +708,7 @@ def run_gc

# This check demonstrates that the threads are sleeping concurrently:
# In the serial case, the difference would be a multiple of sleep time
expect(stop - start).to be_within(0.1).of(sleep_time)
expect(stop - start).to be_within(0.2).of(sleep_time)

expect(values).to match_array(threads.map(&:object_id))
end
Expand Down

0 comments on commit 0f50311

Please sign in to comment.