27
27
} . to raise_error ( Mysql2 ::Error )
28
28
end
29
29
30
- if defined? Encoding
31
- it "should raise an exception on create for invalid encodings" do
32
- expect {
33
- Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "fake" ) )
34
- } . to raise_error ( Mysql2 ::Error )
35
- end
30
+ it "should raise an exception on create for invalid encodings" do
31
+ expect {
32
+ Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "fake" ) )
33
+ } . to raise_error ( Mysql2 ::Error )
34
+ end
36
35
37
- it "should not raise an exception on create for a valid encoding" do
38
- expect {
39
- Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "utf8" ) )
40
- } . not_to raise_error
36
+ it "should not raise an exception on create for a valid encoding" do
37
+ expect {
38
+ Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "utf8" ) )
39
+ } . not_to raise_error
41
40
42
- expect {
43
- Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "big5" ) )
44
- } . not_to raise_error
45
- end
41
+ expect {
42
+ Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => "big5" ) )
43
+ } . not_to raise_error
46
44
end
47
45
48
46
it "should accept connect flags and pass them to #connect" do
@@ -119,9 +117,9 @@ def connect *args
119
117
it "should be able to connect via SSL options" do
120
118
ssl = @client . query "SHOW VARIABLES LIKE 'have_ssl'"
121
119
ssl_uncompiled = ssl . any? { |x | x [ 'Value' ] == 'OFF' }
122
- skip ( "DON'T WORRY, THIS TEST PASSES - but SSL is not compiled into your MySQL daemon." ) if ssl_uncompiled
120
+ pending ( "DON'T WORRY, THIS TEST PASSES - but SSL is not compiled into your MySQL daemon." ) if ssl_uncompiled
123
121
ssl_disabled = ssl . any? { |x | x [ 'Value' ] == 'DISABLED' }
124
- skip ( "DON'T WORRY, THIS TEST PASSES - but SSL is not enabled in your MySQL daemon." ) if ssl_disabled
122
+ pending ( "DON'T WORRY, THIS TEST PASSES - but SSL is not enabled in your MySQL daemon." ) if ssl_disabled
125
123
126
124
# You may need to adjust the lines below to match your SSL certificate paths
127
125
ssl_client = nil
@@ -150,13 +148,15 @@ def connect *args
150
148
end
151
149
152
150
def run_gc
153
- GC . start
154
- sleep ( 1 ) if defined? ( Rubinius ) # Let the Rubinius GC thread do its work
151
+ if defined? ( Rubinius )
152
+ GC . run ( true )
153
+ else
154
+ GC . start
155
+ end
156
+ sleep ( 0.5 )
155
157
end
156
158
157
159
it "should not leave dangling connections after garbage collection" do
158
- skip ( 'Rubinius misbehaves' ) if defined? ( Rubinius )
159
-
160
160
run_gc
161
161
162
162
client = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] )
@@ -173,23 +173,22 @@ def run_gc
173
173
expect ( final_count ) . to eq ( before_count )
174
174
end
175
175
176
- if Process . respond_to? ( :fork )
177
- it "should not close connections when running in a child process" do
178
- run_gc
179
- client = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] )
180
176
181
- fork do
182
- client . query ( 'SELECT 1' )
183
- client = nil
184
- run_gc
185
- end
186
-
187
- Process . wait
177
+ it "should not close connections when running in a child process" do
178
+ run_gc
179
+ client = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] )
188
180
189
- # this will throw an error if the underlying socket was shutdown by the
190
- # child's GC
191
- expect { client . query ( 'SELECT 1' ) } . to_not raise_exception
181
+ fork do
182
+ client . query ( 'SELECT 1' )
183
+ client = nil
184
+ run_gc
192
185
end
186
+
187
+ Process . wait
188
+
189
+ # this will throw an error if the underlying socket was shutdown by the
190
+ # child's GC
191
+ expect { client . query ( 'SELECT 1' ) } . to_not raise_exception
193
192
end
194
193
195
194
it "should be able to connect to database with numeric-only name" do
@@ -272,7 +271,7 @@ def run_gc
272
271
@client_i = Mysql2 ::Client . new DatabaseCredentials [ 'root' ] . merge ( :local_infile => true )
273
272
local = @client_i . query "SHOW VARIABLES LIKE 'local_infile'"
274
273
local_enabled = local . any? { |x | x [ 'Value' ] == 'ON' }
275
- skip ( "DON'T WORRY, THIS TEST PASSES - but LOCAL INFILE is not enabled in your MySQL daemon." ) unless local_enabled
274
+ pending ( "DON'T WORRY, THIS TEST PASSES - but LOCAL INFILE is not enabled in your MySQL daemon." ) unless local_enabled
276
275
277
276
@client_i . query %[
278
277
CREATE TABLE IF NOT EXISTS infileTest (
@@ -418,7 +417,6 @@ def run_gc
418
417
# XXX this test is not deterministic (because Unix signal handling is not)
419
418
# and may fail on a loaded system
420
419
it "should run signal handlers while waiting for a response" do
421
- skip ( 'Rubinius misbehaves' ) if defined? ( Rubinius )
422
420
mark = { }
423
421
trap ( :USR1 ) { mark [ :USR1 ] = Time . now }
424
422
begin
@@ -703,25 +701,25 @@ def run_gc
703
701
expect ( info [ :version ] . class ) . to eql ( String )
704
702
end
705
703
706
- if defined? Encoding
707
- context "strings returned by #info" do
708
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
709
- with_internal_encoding nil do
710
- expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . find ( 'utf-8' ) )
704
+ context "strings returned by #info" do
705
+ before { pending ( 'Encoding is undefined' ) unless defined? ( Encoding ) }
711
706
712
- client2 = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => 'ascii' ) )
713
- expect ( client2 . info [ :version ] . encoding ) . to eql ( Encoding . find ( 'us-ascii' ) )
714
- end
707
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
708
+ with_internal_encoding nil do
709
+ expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . find ( 'utf-8' ) )
710
+
711
+ client2 = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => 'ascii' ) )
712
+ expect ( client2 . info [ :version ] . encoding ) . to eql ( Encoding . find ( 'us-ascii' ) )
715
713
end
714
+ end
716
715
717
- it "should use Encoding.default_internal" do
718
- with_internal_encoding 'utf-8' do
719
- expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
720
- end
716
+ it "should use Encoding.default_internal" do
717
+ with_internal_encoding 'utf-8' do
718
+ expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
719
+ end
721
720
722
- with_internal_encoding 'us-ascii' do
723
- expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
724
- end
721
+ with_internal_encoding 'us-ascii' do
722
+ expect ( @client . info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
725
723
end
726
724
end
727
725
end
@@ -746,25 +744,25 @@ def run_gc
746
744
} . to raise_error ( Mysql2 ::Error )
747
745
end
748
746
749
- if defined? Encoding
750
- context "strings returned by #server_info" do
751
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
752
- with_internal_encoding nil do
753
- expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . find ( 'utf-8' ) )
747
+ context "strings returned by #server_info" do
748
+ before { pending ( 'Encoding is undefined' ) unless defined? ( Encoding ) }
754
749
755
- client2 = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => 'ascii' ) )
756
- expect ( client2 . server_info [ :version ] . encoding ) . to eql ( Encoding . find ( 'us-ascii' ) )
757
- end
750
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
751
+ with_internal_encoding nil do
752
+ expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . find ( 'utf-8' ) )
753
+
754
+ client2 = Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] . merge ( :encoding => 'ascii' ) )
755
+ expect ( client2 . server_info [ :version ] . encoding ) . to eql ( Encoding . find ( 'us-ascii' ) )
758
756
end
757
+ end
759
758
760
- it "should use Encoding.default_internal" do
761
- with_internal_encoding 'utf-8' do
762
- expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
763
- end
759
+ it "should use Encoding.default_internal" do
760
+ with_internal_encoding 'utf-8' do
761
+ expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
762
+ end
764
763
765
- with_internal_encoding 'us-ascii' do
766
- expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
767
- end
764
+ with_internal_encoding 'us-ascii' do
765
+ expect ( @client . server_info [ :version ] . encoding ) . to eql ( Encoding . default_internal )
768
766
end
769
767
end
770
768
end
0 commit comments