mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-28 00:02:22 -05:00
added test for #365
This commit is contained in:
parent
b9bd1547a0
commit
4c9db6f382
@ -16,7 +16,7 @@ class Bug_1_6_2_Test < Minitest::Test
|
||||
.plugin(:persistent)
|
||||
.with(resolver_options: { nameserver: [slow_dns_server.nameserver], timeouts: [1, 3] })
|
||||
|
||||
uri = URI(build_uri("/get"))
|
||||
uri = URI(build_uri("/get", "http://#{httpbin}"))
|
||||
|
||||
response = session.get(uri)
|
||||
verify_status(response, 200)
|
||||
@ -37,9 +37,55 @@ class Bug_1_6_2_Test < Minitest::Test
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def test_coalesce_should_not_leak_across_threads
|
||||
uri = URI(build_uri("/get", "https://#{httpbin}"))
|
||||
coalesced_uri = URI(build_uri("/get", "https://#{ENV["HTTPBIN_COALESCING_HOST"]}"))
|
||||
q = Queue.new
|
||||
|
||||
def scheme
|
||||
"http://"
|
||||
http = HTTPX.plugin(SessionWithPool).plugin(:persistent)
|
||||
|
||||
registered_conns = Set[]
|
||||
http.define_singleton_method(:select_connection) do |conn, selector|
|
||||
registered_conns << [conn, selector]
|
||||
super(conn, selector)
|
||||
end
|
||||
|
||||
http.singleton_class.class_eval do
|
||||
public(:get_current_selector)
|
||||
end
|
||||
|
||||
th1 = Thread.start do
|
||||
q.pop
|
||||
res = http.get(coalesced_uri)
|
||||
verify_status(res, 200)
|
||||
http.get_current_selector
|
||||
end
|
||||
|
||||
th2 = Thread.start do
|
||||
res = http.get(uri)
|
||||
verify_status(res, 200)
|
||||
sel = http.get_current_selector
|
||||
q << :done
|
||||
sel
|
||||
end
|
||||
|
||||
th2_selector = th2.value
|
||||
th1_selector = th1.value
|
||||
|
||||
conns = http.connections.select(&:open?)
|
||||
assert conns.size == 1
|
||||
conn = conns.first
|
||||
assert conn.current_session.nil?, "connection should have reset its session already"
|
||||
assert conn.current_selector.nil?, "connection should have reset its selector already"
|
||||
|
||||
assert http.pool.connections_counter == 1, "connection"
|
||||
assert http.pool.connections.include?(conn)
|
||||
|
||||
assert registered_conns.size == 2
|
||||
|
||||
assert registered_conns.include?([conn, th1_selector])
|
||||
assert registered_conns.include?([conn, th2_selector])
|
||||
ensure
|
||||
http.close if defined?(http)
|
||||
end
|
||||
end
|
||||
|
||||
@ -49,7 +49,7 @@ module SessionWithPool
|
||||
end
|
||||
|
||||
module ConnectionMethods
|
||||
attr_reader :origins, :main_sibling, :sibling
|
||||
attr_reader :origins, :main_sibling, :sibling, :current_session, :current_selector
|
||||
|
||||
def closed?
|
||||
@io.closed?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user