Skip to content

Commit 2607cda

Browse files
committed
Spec for exception if streaming ended due to a timeout
1 parent 5677e2e commit 2607cda

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

spec/mysql2/result_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,35 @@
2727
result.each { |r| r.should_not be_nil}
2828
end
2929

30-
it "#count should be zero for rows after streaming when there were no results " do
30+
it "#count should be zero for rows after streaming when there were no results" do
3131
@client.query "USE test"
3232
result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false)
3333
result.count.should eql(0)
3434
result.each.to_a
3535
result.count.should eql(0)
3636
end
3737

38+
it "should raise an exception if streaming ended due to a timeout" do
39+
# Create an extra client instance, since we're going to time it out
40+
client = Mysql2::Client.new DatabaseCredentials['root']
41+
client.query "CREATE TEMPORARY TABLE streamingTest (val VARCHAR(10))"
42+
43+
# Insert enough records to force the result set into multiple reads
44+
10000.times do |i|
45+
client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
46+
end
47+
48+
client.query "SET net_write_timeout = 1"
49+
res = client.query "SELECT * FROM streamingTest", :stream => true
50+
51+
lambda {
52+
res.each_with_index do |row, i|
53+
# Exhaust the first result packet then trigger a timeout
54+
sleep 2 if i > 0 && i % 1000 == 0
55+
end
56+
}.should raise_error(Mysql2::Error, /Lost connection/)
57+
end
58+
3859
it "should have included Enumerable" do
3960
Mysql2::Result.ancestors.include?(Enumerable).should be_true
4061
end

0 commit comments

Comments
 (0)