Implements timeouts for synchronous HttpClient.
This commit is contained in:
parent
3c47e70d53
commit
0c99523ad3
2 changed files with 35 additions and 9 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import strutils
|
||||
from net import TimeoutError
|
||||
|
||||
import httpclient, asyncdispatch
|
||||
|
||||
|
|
@ -30,6 +31,18 @@ proc syncTest() =
|
|||
resp = client.request("https://google.com/")
|
||||
doAssert(resp.code.is2xx or resp.code.is3xx)
|
||||
|
||||
client.close()
|
||||
|
||||
# Timeout test.
|
||||
client = newHttpClient(timeout = 1)
|
||||
try:
|
||||
resp = client.request("http://example.com/")
|
||||
doAssert false, "TimeoutError should have been raised."
|
||||
except TimeoutError:
|
||||
discard
|
||||
except:
|
||||
doAssert false, "TimeoutError should have been raised."
|
||||
|
||||
syncTest()
|
||||
|
||||
waitFor(asyncTest())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue