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

Fix test failures on MariaDB #1193

Merged
merged 7 commits into from
May 19, 2021
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
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ jobs:
# db: A DB's brew package name in macOS case.
# Set a name "db: '[email protected]'" when using an old version.
# MariaDB lastet version
# Allow failure due to the following test failures.
# https://github.com/brianmario/mysql2/issues/965
# https://github.com/brianmario/mysql2/issues/1152
# Allow failure due to the following test failures that rarely happens.
# https://github.com/brianmario/mysql2/issues/1194
- {os: macos-latest, ruby: 2.4, db: mariadb, allow-failure: true}
# MySQL latest version
# Allow failure due to the issue #1165.
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ jobs:
# CentOS 7 system Ruby is the fixed version 2.0.0.
- {distro: centos, image: 'centos:7', name_extra: 'ruby 2.0.0'}
# Fedora latest stable version
# Allow failure due to the following test failures.
# https://github.com/brianmario/mysql2/issues/965
- {distro: fedora, image: 'fedora:latest', allow-failure: true}
- {distro: fedora, image: 'fedora:latest'}
# Fedora development version
# Allow failure due to the following test failures.
# https://github.com/brianmario/mysql2/issues/1152
- {distro: fedora, image: 'fedora:rawhide', allow-failure: true}
- {distro: fedora, image: 'fedora:rawhide'}
# 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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ matrix:
- mysql2gem.example.com
fast_finish: true
allow_failures:
# Allow failure due to a package repository not found for now.
# https://travis-ci.org/github/brianmario/mysql2/jobs/767276558#L1255
- env: DB=mysql55
3 changes: 2 additions & 1 deletion ci/Dockerfile_fedora
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN dnf -yq install \
redhat-rpm-config \
ruby-devel \
rubygem-bigdecimal \
rubygem-bundler
rubygem-bundler \
rubygem-json

CMD bash ci/container.sh
7 changes: 7 additions & 0 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'spec_helper'

RSpec.describe Mysql2::Client do # rubocop:disable Metrics/BlockLength
let(:performance_schema_enabled) do
performance_schema = @client.query "SHOW VARIABLES LIKE 'performance_schema'"
performance_schema.any? { |x| x['Value'] == 'ON' }
end

context "using defaults file" do
let(:cnf_file) { File.expand_path('../../my.cnf', __FILE__) }

Expand Down Expand Up @@ -479,6 +484,7 @@ def run_gc
end

it "should set default program_name in connect_attrs" do
skip("DON'T WORRY, THIS TEST PASSES - but PERFORMANCE SCHEMA is not enabled in your MySQL daemon.") unless performance_schema_enabled
client = new_client
if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
Expand All @@ -488,6 +494,7 @@ def run_gc
end

it "should set custom connect_attrs" do
skip("DON'T WORRY, THIS TEST PASSES - but PERFORMANCE SCHEMA is not enabled in your MySQL daemon.") unless performance_schema_enabled
client = new_client(connect_attrs: { program_name: 'my_program_name', foo: 'fooval', bar: 'barval' })
if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
Expand Down
14 changes: 13 additions & 1 deletion spec/mysql2/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
end
end

let(:server_info) do
@client.server_info
end

before do
# sanity check
expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
Expand All @@ -56,7 +60,15 @@
expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
expect(bad_err.message).to be_valid_encoding

expect(bad_err.message).to include("??}\u001F")
# MariaDB 10.5 returns a little different error message unlike MySQL
# and other old MariaDBs.
# https://jira.mariadb.org/browse/MDEV-25400
err_str = if server_info[:version].match(/MariaDB/) && server_info[:id] >= 100500
"??}\\001F"
else
"??}\u001F"
end
expect(bad_err.message).to include(err_str)
end
end

Expand Down
15 changes: 11 additions & 4 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
@client = new_client(encoding: "utf8")
end

let(:performance_schema_enabled) do
performance_schema = @client.query "SHOW VARIABLES LIKE 'performance_schema'"
performance_schema.any? { |x| x['Value'] == 'ON' }
end

def stmt_count
# Use the performance schema in MySQL 5.7 and above
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
rescue Mysql2::Error
# Fall back to the global prepapred statement counter
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
if performance_schema_enabled
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
else
# Fall back to the global prepapred statement counter
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
end
end

it "should create a statement" do
Expand Down