Skip to content

Commit a825ba1

Browse files
authored
Merge pull request #1193 from junaruga/wip/fix-tests-mariadb
Fix test failures on MariaDB
2 parents 346b4a4 + 620e15f commit a825ba1

File tree

7 files changed

+40
-15
lines changed

7 files changed

+40
-15
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ jobs:
4040
# db: A DB's brew package name in macOS case.
4141
# Set a name "db: '[email protected]'" when using an old version.
4242
# MariaDB lastet version
43-
# Allow failure due to the following test failures.
44-
# https://github.com/brianmario/mysql2/issues/965
45-
# https://github.com/brianmario/mysql2/issues/1152
43+
# Allow failure due to the following test failures that rarely happens.
44+
# https://github.com/brianmario/mysql2/issues/1194
4645
- {os: macos-latest, ruby: 2.4, db: mariadb, allow-failure: true}
4746
# MySQL latest version
4847
# Allow failure due to the issue #1165.

.github/workflows/container.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ jobs:
1414
# CentOS 7 system Ruby is the fixed version 2.0.0.
1515
- {distro: centos, image: 'centos:7', name_extra: 'ruby 2.0.0'}
1616
# Fedora latest stable version
17-
# Allow failure due to the following test failures.
18-
# https://github.com/brianmario/mysql2/issues/965
19-
- {distro: fedora, image: 'fedora:latest', allow-failure: true}
17+
- {distro: fedora, image: 'fedora:latest'}
2018
# Fedora development version
21-
# Allow failure due to the following test failures.
22-
# https://github.com/brianmario/mysql2/issues/1152
23-
- {distro: fedora, image: 'fedora:rawhide', allow-failure: true}
19+
- {distro: fedora, image: 'fedora:rawhide'}
2420
# On the fail-fast: true, it cancels all in-progress jobs
2521
# if any matrix job fails unlike Travis fast_finish.
2622
fail-fast: false

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ matrix:
4141
- mysql2gem.example.com
4242
fast_finish: true
4343
allow_failures:
44+
# Allow failure due to a package repository not found for now.
45+
# https://travis-ci.org/github/brianmario/mysql2/jobs/767276558#L1255
46+
- env: DB=mysql55

ci/Dockerfile_fedora

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN dnf -yq install \
2020
redhat-rpm-config \
2121
ruby-devel \
2222
rubygem-bigdecimal \
23-
rubygem-bundler
23+
rubygem-bundler \
24+
rubygem-json
2425

2526
CMD bash ci/container.sh

spec/mysql2/client_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'spec_helper'
22

33
RSpec.describe Mysql2::Client do # rubocop:disable Metrics/BlockLength
4+
let(:performance_schema_enabled) do
5+
performance_schema = @client.query "SHOW VARIABLES LIKE 'performance_schema'"
6+
performance_schema.any? { |x| x['Value'] == 'ON' }
7+
end
8+
49
context "using defaults file" do
510
let(:cnf_file) { File.expand_path('../../my.cnf', __FILE__) }
611

@@ -479,6 +484,7 @@ def run_gc
479484
end
480485

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

490496
it "should set custom connect_attrs" do
497+
skip("DON'T WORRY, THIS TEST PASSES - but PERFORMANCE SCHEMA is not enabled in your MySQL daemon.") unless performance_schema_enabled
491498
client = new_client(connect_attrs: { program_name: 'my_program_name', foo: 'fooval', bar: 'barval' })
492499
if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
493500
pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')

spec/mysql2/error_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
end
4040
end
4141

42+
let(:server_info) do
43+
@client.server_info
44+
end
45+
4246
before do
4347
# sanity check
4448
expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
@@ -56,7 +60,15 @@
5660
expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
5761
expect(bad_err.message).to be_valid_encoding
5862

59-
expect(bad_err.message).to include("??}\u001F")
63+
# MariaDB 10.5 returns a little different error message unlike MySQL
64+
# and other old MariaDBs.
65+
# https://jira.mariadb.org/browse/MDEV-25400
66+
err_str = if server_info[:version].match(/MariaDB/) && server_info[:id] >= 100500
67+
"??}\\001F"
68+
else
69+
"??}\u001F"
70+
end
71+
expect(bad_err.message).to include(err_str)
6072
end
6173
end
6274

spec/mysql2/statement_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
@client = new_client(encoding: "utf8")
66
end
77

8+
let(:performance_schema_enabled) do
9+
performance_schema = @client.query "SHOW VARIABLES LIKE 'performance_schema'"
10+
performance_schema.any? { |x| x['Value'] == 'ON' }
11+
end
12+
813
def stmt_count
914
# Use the performance schema in MySQL 5.7 and above
10-
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
11-
rescue Mysql2::Error
12-
# Fall back to the global prepapred statement counter
13-
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
15+
if performance_schema_enabled
16+
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
17+
else
18+
# Fall back to the global prepapred statement counter
19+
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
20+
end
1421
end
1522

1623
it "should create a statement" do

0 commit comments

Comments
 (0)