Commits

larskanis committed 0b318fe

Improve spec for Connection#set_single_row_mode

Comments (0)

Files changed (1)

spec/pg/connection_spec.rb

 			end
 
 			it "should receive rows before entire query is finished" do
-				# The full query needs at minimum 1 second to complete
-				@conn.send_query( "SELECT generate_series(0,999), NULL UNION ALL SELECT generate_series(1000,1999), pg_sleep(0.001);" )
+				@conn.send_query( "SELECT generate_series(0,999), NULL UNION ALL SELECT 1000, pg_sleep(1);" )
 				@conn.set_single_row_mode
 
 				start_time = Time.now
 				first_row_time = nil
 				loop do
-					@conn.block
-					@conn.get_result or break
+					res = @conn.get_result or break
+					res.check
 					first_row_time = Time.now unless first_row_time
 				end
+				(Time.now - start_time).should >= 1.0
 				(first_row_time - start_time).should < 1.0
 			end
+
+			it "should receive rows before entire query fails" do
+				@conn.exec( "CREATE FUNCTION errfunc() RETURNS int AS $$ BEGIN RAISE 'test-error'; END; $$ LANGUAGE plpgsql;" )
+				@conn.send_query( "SELECT generate_series(0,999), NULL UNION ALL SELECT 1000, errfunc();" )
+				@conn.set_single_row_mode
+
+				first_result = nil
+				expect do
+					loop do
+						res = @conn.get_result or break
+						res.check
+						first_result ||= res
+					end
+				end.to raise_error(PG::Error)
+				first_result.kind_of?(PG::Result).should be_true
+				first_result.result_status.should == PG::PGRES_SINGLE_TUPLE
+			end
 		end
 	end
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.