respect connection timeout (#1458)

* pass timeout to ensure connection function

* test connection respect its timeout
This commit is contained in:
Mehdi Pourfar 2021-12-24 12:51:44 +03:30 committed by GitHub
parent 47781af050
commit a9c4f9837c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -837,7 +837,7 @@ class Connection:
return self.transport.qos_semantics_matches_spec(self.connection)
def _extract_failover_opts(self):
conn_opts = {}
conn_opts = {'timeout': self.connect_timeout}
transport_opts = self.transport_options
if transport_opts:
if 'max_retries' in transport_opts:

View File

@ -587,6 +587,16 @@ class test_Connection:
conn = Connection('example.com;example.com;')
assert conn.as_uri() == 'amqp://guest:**@example.com:5672//'
def test_connection_respect_its_timeout(self):
invalid_port = 1222
with Connection(
f'amqp://guest:guest@localhost:{invalid_port}//',
transport_options={'max_retries': 2},
connect_timeout=1
) as conn:
with pytest.raises(OperationalError):
conn.default_channel
class test_Connection_with_transport_options: