From 835f0378adebc7ccb5659d990d5bd295fd18e0c0 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 8 Jun 2022 13:09:58 +0200 Subject: [PATCH] Move specs to "OS thread support" into async file These specs don't run reliable with sync methods. They sometimes block indefinitely. --- spec/pg/connection_async_spec.rb | 28 ++++++++++++++++++++++++++++ spec/pg/connection_spec.rb | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/spec/pg/connection_async_spec.rb b/spec/pg/connection_async_spec.rb index 594da602e..33937888e 100644 --- a/spec/pg/connection_async_spec.rb +++ b/spec/pg/connection_async_spec.rb @@ -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 diff --git a/spec/pg/connection_spec.rb b/spec/pg/connection_spec.rb index 6560fe47c..a464746d7 100644 --- a/spec/pg/connection_spec.rb +++ b/spec/pg/connection_spec.rb @@ -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{