Skip to content

Commit

Permalink
Move specs to "OS thread support" into async file
Browse files Browse the repository at this point in the history
These specs don't run reliable with sync methods.
They sometimes block indefinitely.
  • Loading branch information
larskanis committed Jun 8, 2022
1 parent b273c9c commit 835f037
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 28 additions & 0 deletions spec/pg/connection_async_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,32 @@ def interrupt_thread(exc=nil)
expect( signal_received ).to be_truthy
end

context "OS thread support" do
it "Connection#exec shouldn't block a second thread" do
t = Thread.new do
@conn.exec( "select pg_sleep(1)" )
end

sleep 0.1
expect( t ).to be_alive()
t.kill
@conn.cancel
end

it "Connection.new shouldn't block a second thread" do
serv = nil
t = Thread.new do
serv = TCPServer.new( '127.0.0.1', 54320 )
expect {
described_class.connect( '127.0.0.1', 54320, "", "", "me", "xxxx", "somedb" )
}.to raise_error(PG::ConnectionBad, /server closed the connection unexpectedly/)
end

sleep 0.5
expect( t ).to be_alive()
serv.close
t.join
end
end

end
28 changes: 0 additions & 28 deletions spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2167,34 +2167,6 @@
end
end

context "OS thread support" do
it "Connection#exec shouldn't block a second thread" do
t = Thread.new do
@conn.exec( "select pg_sleep(1)" )
end

sleep 0.1
expect( t ).to be_alive()
t.kill
@conn.cancel
end

it "Connection.new shouldn't block a second thread" do
serv = nil
t = Thread.new do
serv = TCPServer.new( '127.0.0.1', 54320 )
expect {
described_class.connect( '127.0.0.1', 54320, "", "", "me", "xxxx", "somedb" )
}.to raise_error(PG::ConnectionBad, /server closed the connection unexpectedly/)
end

sleep 0.5
expect( t ).to be_alive()
serv.close
t.join
end
end

describe "type casting" do
it "should raise an error on invalid param mapping" do
expect{
Expand Down

0 comments on commit 835f037

Please sign in to comment.