@@ -27,6 +27,40 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
27
27
@adapter . disconnect!
28
28
end
29
29
30
+ test ".new_client" do
31
+ client = @adapter . class . new_client ( @configuration )
32
+ assert_equal Trilogy , client . class
33
+ end
34
+
35
+ test ".new_client on db error" do
36
+ configuration = @configuration . merge ( database : "unknown" )
37
+ assert_raises ActiveRecord ::NoDatabaseError do
38
+ @adapter . class . new_client ( configuration )
39
+ end
40
+ end
41
+
42
+ test ".new_client on access denied error" do
43
+ skip ( "Test fails intermittently with TRILOGY_PROTOCOL_VIOLATION. See https://github.com/github/trilogy/pull/42" )
44
+ configuration = @configuration . merge ( username : "unknown" )
45
+ assert_raises ActiveRecord ::DatabaseConnectionError do
46
+ @adapter . class . new_client ( configuration )
47
+ end
48
+ end
49
+
50
+ test ".new_client on host error" do
51
+ configuration = @configuration . merge ( host : "unknown" )
52
+ assert_raises ActiveRecord ::DatabaseConnectionError do
53
+ @adapter . class . new_client ( configuration )
54
+ end
55
+ end
56
+
57
+ test ".new_client on port error" do
58
+ configuration = @configuration . merge ( port : 1234 )
59
+ assert_raises ActiveRecord ::ConnectionNotEstablished do
60
+ @adapter . class . new_client ( configuration )
61
+ end
62
+ end
63
+
30
64
test "#explain for one query" do
31
65
explain = @adapter . explain ( "select * from posts" )
32
66
assert_match %(possible_keys) , explain
@@ -121,7 +155,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
121
155
end
122
156
123
157
test "#active? answers false with connection and exception" do
124
- @adapter . send ( :connection ) . stub ( :ping , -> { raise Trilogy ::Error . new } ) do
158
+ @adapter . send ( :connection ) . stub ( :ping , -> { raise Trilogy ::BaseError . new } ) do
125
159
assert_equal false , @adapter . active?
126
160
end
127
161
end
@@ -147,11 +181,11 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
147
181
adapter = trilogy_adapter_with_connection ( old_connection )
148
182
149
183
begin
150
- Trilogy . stub ( :new , -> _ { raise Trilogy ::Error . new } ) do
184
+ Trilogy . stub ( :new , -> _ { raise Trilogy ::BaseError . new } ) do
151
185
adapter . reconnect!
152
186
end
153
187
rescue ActiveRecord ::StatementInvalid => ex
154
- assert_instance_of Trilogy ::Error , ex . cause
188
+ assert_instance_of Trilogy ::BaseError , ex . cause
155
189
else
156
190
flunk "Expected Trilogy::Error to be raised"
157
191
end
@@ -381,7 +415,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
381
415
382
416
# Cause an ER_SERVER_SHUTDOWN error (code 1053) after the session is
383
417
# set. On reconnect, the adapter will get a real, working connection.
384
- server_shutdown_error = Trilogy ::DatabaseError . new
418
+ server_shutdown_error = Trilogy ::ProtocolError . new
385
419
server_shutdown_error . instance_variable_set ( :@error_code , 1053 )
386
420
mock_connection . expect ( :query , nil ) { raise server_shutdown_error }
387
421
@@ -416,7 +450,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
416
450
assert adapter . active?
417
451
418
452
# Make connection lost for future queries by exceeding the read timeout
419
- assert_raises ( Errno :: ETIMEDOUT ) do
453
+ assert_raises ( Trilogy :: TimeoutError ) do
420
454
connection . query "SELECT sleep(2);"
421
455
end
422
456
assert_not adapter . active?
@@ -497,7 +531,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
497
531
adapter . execute ( "SELECT 1" )
498
532
499
533
# Cause the client to disconnect without the adapter's awareness
500
- assert_raises Errno :: ETIMEDOUT do
534
+ assert_raises Trilogy :: TimeoutError do
501
535
adapter . send ( :connection ) . query ( "SELECT sleep(2)" )
502
536
end
503
537
@@ -519,7 +553,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
519
553
adapter . execute ( "SELECT 1" )
520
554
521
555
# Cause the client to disconnect without the adapter's awareness
522
- assert_raises Errno :: ETIMEDOUT do
556
+ assert_raises Trilogy :: TimeoutError do
523
557
adapter . send ( :connection ) . query ( "SELECT sleep(2)" )
524
558
end
525
559
end
@@ -558,7 +592,7 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
558
592
test "#execute fails with unknown error" do
559
593
assert_raises_with_message ( ActiveRecord ::StatementInvalid , /A random error/ ) do
560
594
connection = Minitest ::Mock . new Trilogy . new ( @configuration )
561
- connection . expect ( :query , nil ) { raise Trilogy ::DatabaseError , "A random error." }
595
+ connection . expect ( :query , nil ) { raise Trilogy ::ProtocolError , "A random error." }
562
596
adapter = trilogy_adapter_with_connection ( connection )
563
597
564
598
adapter . execute "SELECT * FROM posts;"
0 commit comments