Skip to content

Commit 1a6e1be

Browse files
committed
GitHub Actions: Add macOS cases.
* 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)>' ```
1 parent 1231863 commit 1a6e1be

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

.github/workflows/ubuntu.yml renamed to .github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Ubuntu
1+
name: Build
22
on: [push, pull_request]
33
jobs:
44
build:
@@ -38,6 +38,12 @@ jobs:
3838
# `service mysql restart` fails.
3939
- {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true}
4040
- {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true}
41+
# db: the DB's brew package name in macOS case.
42+
# Allow failure due to the following test failures.
43+
# https://github.com/brianmario/mysql2/issues/965
44+
- {os: macos-latest, ruby: 2.4, db: '[email protected]', allow-failure: true}
45+
# Allow failure due to Mysql2::Error: Unknown system variable 'session_track_system_variables'.
46+
- {os: macos-latest, ruby: 2.4, db: '[email protected]', allow-failure: true}
4147
# On the fail-fast: true, it cancels all in-progress jobs
4248
# if any matrix job fails unlike Travis fast_finish.
4349
fail-fast: false

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,5 @@ matrix:
4949
addons:
5050
hosts:
5151
- mysql2gem.example.com
52-
- os: osx
53-
rvm: 2.4
54-
env: DB=mysql56
55-
addons:
56-
hosts:
57-
- mysql2gem.example.com
5852
fast_finish: true
5953
allow_failures:
60-
- os: osx
61-
rvm: 2.4
62-
env: DB=mysql56

.travis_setup.sh

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,23 @@ if [[ -n ${GITHUB_ACTIONS-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
7676
CHANGED_PASSWORD=true
7777
fi
7878

79-
# Install MySQL if OS=darwin
79+
# Install MySQL/MariaDB if OS=darwin
8080
if [[ x$OSTYPE =~ ^xdarwin ]]; then
81-
brew update
81+
brew update > /dev/null
82+
83+
# Check available packages.
84+
for KEYWORD in mysql mariadb; do
85+
brew search "${KEYWORD}"
86+
done
87+
8288
brew install "$DB" mariadb-connector-c
83-
$(brew --prefix "$DB")/bin/mysql.server start
89+
DB_PREFIX="$(brew --prefix "${DB}")"
90+
export PATH="${DB_PREFIX}/bin:${PATH}"
91+
export LDFLAGS="-L${DB_PREFIX}/lib"
92+
export CPPFLAGS="-I${DB_PREFIX}/include"
93+
94+
mysql.server start
95+
CHANGED_PASSWORD_BY_RECREATE=true
8496
fi
8597

8698
# TODO: get SSL working on OS X in Travis
@@ -89,13 +101,11 @@ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
89101
sudo service mysql restart
90102
fi
91103

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

106+
MYSQL_OPTS=''
107+
DB_SYS_USER=root
108+
if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
99109
if [[ -n ${GITHUB_ACTIONS-} && -f /etc/mysql/debian.cnf ]]; then
100110
MYSQL_OPTS='--defaults-extra-file=/etc/mysql/debian.cnf'
101111
# Install from packages in OS official packages.
@@ -106,25 +116,20 @@ else
106116
# xenial
107117
DB_SYS_USER=root
108118
fi
109-
else
110-
# Install from official mysql packages.
111-
MYSQL_OPTS=''
112-
DB_SYS_USER=root
113119
fi
120+
fi
114121

115-
if [ "${CHANGED_PASSWORD}" = true ]; then
116-
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
117-
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
118-
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
119-
elif [ "${CHANGED_PASSWORD_BY_RECREATE}" = true ]; then
120-
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
122+
if [ "${CHANGED_PASSWORD}" = true ]; then
123+
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
124+
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
125+
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
126+
elif [ "${CHANGED_PASSWORD_BY_RECREATE}" = true ]; then
127+
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
121128
DROP USER 'root'@'localhost';
122129
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
123130
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
124131
FLUSH PRIVILEGES;
125132
SQL
126-
fi
127-
128-
# IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
129-
mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
130133
fi
134+
135+
mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'

spec/mysql2/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def run_gc
629629
end
630630

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

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

713713
expect(values).to match_array(threads.map(&:object_id))
714714
end

0 commit comments

Comments
 (0)