Skip to content

Commit 1c2f56e

Browse files
committed
Add test case for when connection is dead and tiny_tds raises an error
1 parent 3202303 commit 1c2f56e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/client_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ class ClientTest < TinyTds::TestCase
132132
end
133133
end
134134

135+
it 'raises TinyTds exception when tcp socket is down' do
136+
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
137+
begin
138+
client = new_connection timeout: 2, port: 1234
139+
assert_client_works(client)
140+
action = lambda { client.execute("waitfor delay '00:00:01'").do }
141+
142+
# Use toxiproxy to close the TCP socket immediately.
143+
# We want TinyTds to fail to execute the statement and raise an error immediately.
144+
Toxiproxy[:sqlserver_test].down do
145+
assert_raise_tinytds_error(action) do |e|
146+
assert_match %r{failed to execute statement}i, e.message, 'ignore if non-english test run'
147+
end
148+
end
149+
ensure
150+
assert_new_connections_work
151+
end
152+
end
153+
135154
it 'raises TinyTds exception with tcp socket network failure' do
136155
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
137156
begin

0 commit comments

Comments
 (0)