Skip to content

Commit e5795ca

Browse files
committed
Pool: Make Pool#client method public
1 parent b79177f commit e5795ca

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

spec/helpers/networking/connection_pool_spec.cr

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,24 @@ Spectator.describe Invidious::ConnectionPool do
5858
expect(pool.post("/post") { |r| r.body_io.gets_to_end }).to eq("post")
5959
end
6060

61-
# it "Can checkout a client" do
62-
# end
61+
it "Allows more than one clients to be checked out (if applicable)" do
62+
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
63+
64+
pool.checkout do | client |
65+
expect(pool.post("/post").body).to eq("post")
66+
end
67+
end
68+
69+
it "Can make multiple requests with the same client" do
70+
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)
71+
72+
pool.checkout do | client |
73+
expect(client.get("/get").body).to eq("get")
74+
expect(client.post("/post").body).to eq("post")
75+
expect(client.get("/get").body).to eq("get")
76+
end
77+
78+
end
6379

6480
it "Allows concurrent requests" do
6581
pool = Invidious::ConnectionPool::Pool.new(URI.parse("http://localhost:12345"), max_capacity: 100)

src/invidious/connection/pool.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Invidious::ConnectionPool
3232
# Streaming API for {{method.id.upcase}} request.
3333
# The response will have its body as an `IO` accessed via `HTTP::Client::Response#body_io`.
3434
def {{method.id}}(*args, **kwargs, &)
35-
self.client do | client |
35+
self.checkout do | client |
3636
client.{{method.id}}(*args, **kwargs) do | response |
3737

3838
result = yield response
@@ -47,14 +47,14 @@ module Invidious::ConnectionPool
4747
# Executes a {{method.id.upcase}} request.
4848
# The response will have its body as a `String`, accessed via `HTTP::Client::Response#body`.
4949
def {{method.id}}(*args, **kwargs)
50-
self.client do | client |
50+
self.checkout do | client |
5151
return client.{{method.id}}(*args, **kwargs)
5252
end
5353
end
5454
{% end %}
5555

5656
# Checks out a client in the pool
57-
private def client(&)
57+
def checkout(&)
5858
# If a client has been deleted from the pool
5959
# we won't try to release it
6060
client_exists_in_pool = true

0 commit comments

Comments
 (0)