File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,24 @@ Spectator.describe Invidious::ConnectionPool do
58
58
expect(pool.post(" /post" ) { |r | r.body_io.gets_to_end }).to eq(" post" )
59
59
end
60
60
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
63
79
64
80
it " Allows concurrent requests" do
65
81
pool = Invidious ::ConnectionPool ::Pool .new(URI .parse(" http://localhost:12345" ), max_capacity: 100 )
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ module Invidious::ConnectionPool
32
32
# Streaming API for {{method.id.upcase}} request.
33
33
# The response will have its body as an `IO` accessed via `HTTP::Client::Response#body_io`.
34
34
def {{method.id}} (* args , ** kwargs, & )
35
- self .client do | client |
35
+ self .checkout do | client |
36
36
client.{{method.id}}(* args, ** kwargs) do | response |
37
37
38
38
result = yield response
@@ -47,14 +47,14 @@ module Invidious::ConnectionPool
47
47
# Executes a {{method.id.upcase}} request.
48
48
# The response will have its body as a `String`, accessed via `HTTP::Client::Response#body`.
49
49
def {{method.id}} (* args , ** kwargs)
50
- self .client do | client |
50
+ self .checkout do | client |
51
51
return client.{{method.id}}(* args, ** kwargs)
52
52
end
53
53
end
54
54
{% end % }
55
55
56
56
# Checks out a client in the pool
57
- private def client (& )
57
+ def checkout (& )
58
58
# If a client has been deleted from the pool
59
59
# we won't try to release it
60
60
client_exists_in_pool = true
You can’t perform that action at this time.
0 commit comments