Skip to content

Commit 890345e

Browse files
committed
Emit warning warning when changing automatic_close on Windows
1 parent 100435c commit 890345e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

ext/mysql2/client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ static VALUE set_automatic_close(VALUE self, VALUE value) {
11121112
#ifndef _WIN32
11131113
wrapper->automatic_close = 0;
11141114
#else
1115-
rb_raise(cMysql2Error, "Connections are always closed by garbage collector on Windows");
1115+
rb_warn("Connections are always closed by garbage collector on Windows");
11161116
#endif
11171117
}
11181118
return value;

spec/mysql2/client_spec.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# encoding: UTF-8
22
require 'spec_helper'
3+
require 'stringio'
34

45
RSpec.describe Mysql2::Client do
56
context "using defaults file" do
@@ -197,14 +198,22 @@ def run_gc
197198

198199
if RUBY_PLATFORM =~ /mingw|mswin/
199200
it "cannot be disabled" do
200-
expect {
201+
stderr, $stderr = $stderr, StringIO.new
202+
203+
begin
201204
Mysql2::Client.new(DatabaseCredentials['root'].merge(:automatic_close => false))
202-
}.to raise_error(Mysql2::Error)
205+
expect($stderr.string).to include('always closed by garbage collector')
206+
$stderr.reopen
203207

204-
client = Mysql2::Client.new(DatabaseCredentials['root'])
208+
client = Mysql2::Client.new(DatabaseCredentials['root'])
209+
client.automatic_close = false
210+
expect($stderr.string).to include('always closed by garbage collector')
211+
$stderr.reopen
205212

206-
expect { client.automatic_close = false }.to raise_error(Mysql2::Error)
207-
expect { client.automatic_close = true }.to_not raise_error
213+
expect { client.automatic_close = true }.to_not change { $stderr.string }
214+
ensure
215+
$stderr = stderr
216+
end
208217
end
209218
else
210219
it "can be configured" do

0 commit comments

Comments
 (0)