Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 2d60b07

Browse files
committedNov 26, 2019
Fix flaky test_timeout
We had an interesting test failure in CI where this test failed twice in a row: we were expecting a timeout in 0.001 seconds, but both times it took more than one second! How can this happen? Well, when we ask a request to timeout after N seconds, here's what we know: * the request will time out, eventually * it won't timeout before those N seconds * it could timeout a long time after those N seconds, especially on a busy CI service Let's take advantage of those facts by specifying a request-specific timeout that's longer than the pool-level timeout and making sure that the timeout was long indeed. We still test that the request-specific timeout overrides the pool-level timeout, but will stop failing on busy CI services.
1 parent 32b88b7 commit 2d60b07

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎test/with_dummyserver/test_connectionpool.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ def test_timeout(self):
9393

9494
# Request-specific timeouts should raise errors
9595
with HTTPConnectionPool(
96-
self.host, self.port, timeout=LONG_TIMEOUT, retries=False
96+
self.host, self.port, timeout=short_timeout, retries=False
9797
) as pool:
9898
wait_for_socket(ready_event)
9999
now = time.time()
100100
with pytest.raises(ReadTimeoutError):
101-
pool.request("GET", "/", timeout=short_timeout)
101+
pool.request("GET", "/", timeout=LONG_TIMEOUT)
102102
delta = time.time() - now
103103

104-
message = "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT"
105-
assert delta < LONG_TIMEOUT, message
104+
message = "timeout was pool-level SHORT_TIMEOUT rather than request-level LONG_TIMEOUT"
105+
assert delta >= LONG_TIMEOUT, message
106106
block_event.set() # Release request
107107

108108
# Timeout passed directly to request should raise a request timeout

0 commit comments

Comments
 (0)
This repository has been archived.