forked from ged/ruby-pg
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add async_connect and async_send methods and add specific specs for F…
…iber.scheduler Fixes ged#342
- Loading branch information
Showing
4 changed files
with
269 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- rspec -*- | ||
#encoding: utf-8 | ||
|
||
require_relative '../helpers' | ||
|
||
context "with a Fiber scheduler" do | ||
def setup | ||
# Run examples with gated scheduler | ||
sched = Helpers::TcpGateScheduler.new(external_host: 'localhost', external_port: ENV['PGPORT'].to_i) | ||
Fiber.set_scheduler(sched) | ||
@conninfo_gate = @conninfo.gsub(/(^| )port=\d+/, " port=#{sched.internal_port}") | ||
|
||
# Run examples with default scheduler | ||
#Fiber.set_scheduler(Helpers::Scheduler.new) | ||
#@conninfo_gate = @conninfo | ||
|
||
# Run examples without scheduler | ||
#def Fiber.schedule; yield; end | ||
#@conninfo_gate = @conninfo | ||
end | ||
|
||
def teardown | ||
Fiber.set_scheduler(nil) | ||
end | ||
|
||
def stop_scheduler | ||
if Fiber.scheduler && Fiber.scheduler.respond_to?(:finish) | ||
Fiber.scheduler.finish | ||
end | ||
end | ||
|
||
it "connects to a server" do | ||
Thread.new do | ||
setup | ||
Fiber.schedule do | ||
conn = PG.connect(@conninfo_gate) | ||
|
||
res = conn.exec_params("SELECT 7", []) | ||
expect(res.values).to eq([["7"]]) | ||
|
||
conn.finish | ||
stop_scheduler | ||
end | ||
end.join | ||
end | ||
|
||
it "waits when sending data" do | ||
Thread.new do | ||
setup | ||
Fiber.schedule do | ||
conn = PG.connect(@conninfo_gate) | ||
|
||
data = "x" * 1000 * 1000 * 10 | ||
res = conn.exec_params("SELECT LENGTH($1)", [data]) | ||
expect(res.values).to eq([[data.length.to_s]]) | ||
|
||
conn.finish | ||
stop_scheduler | ||
end | ||
end.join | ||
end | ||
|
||
it "connects several times" do | ||
Thread.new do | ||
setup | ||
Fiber.schedule do | ||
3.times do | ||
conn = PG.connect(@conninfo_gate) | ||
conn.finish | ||
end | ||
stop_scheduler | ||
end | ||
end.join | ||
end | ||
|
||
end |