added a test for when an http/2 connection exhausts and a second connection has to be established

This commit is contained in:
HoneyryderChuck 2020-11-26 17:12:09 +00:00
parent 264278a7ce
commit 322aa06f22
3 changed files with 44 additions and 4 deletions

View File

@ -51,10 +51,6 @@ module HTTPX
:rw
end
def reset
init_connection
end
def close(*args)
@connection.goaway(*args) unless @connection.state == :closed
emit(:close)
@ -163,6 +159,9 @@ module HTTPX
@connection.send_connection_preface
end
alias_method :reset, :init_connection
public :reset
def handle_stream(stream, request)
stream.on(:close, &method(:on_stream_close).curry[stream, request])
stream.on(:half_close) do

View File

@ -75,6 +75,16 @@ class HTTPSTest < Minitest::Test
assert log_output.match(/HEADER: content-length: \d+/)
end
def test_http2_max_streams
uri = build_uri("/get")
HTTPX.plugin(SessionWithSingleStream).plugin(SessionWithPool).wrap do |http|
http.get(uri, uri)
connection_count = http.pool.connection_count
assert connection_count == 2, "expected to have 2 connections, instead have #{connection_count}"
assert http.connection_exausted, "expected 1 connnection to have exhausted"
end
end
private
def origin(orig = httpbin)

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
#
# This module is used only to test transitions from a full HTTP/2 connection when it
# exhausts the number of streamss
#
module SessionWithSingleStream
module ConnectionMethods
def build_parser
parser = super
def parser.exhausted?
@connection.active_stream_count.positive?
end
parser.instance_variable_set(:@max_requests, 10)
connection = parser.instance_variable_get(:@connection)
connection.max_streams = 1
parser
end
end
module InstanceMethods
attr_reader :connection_exausted
def set_connection_callbacks(connection, connections, options)
super
connection.on(:exhausted) do
@connection_exausted = true
end
end
end
end