diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-03-23 00:37:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 08:37:15 +0100 |
commit | 1d19cd660f39b9e76005b849ae1f7ca966278438 (patch) | |
tree | 8caf3cf1b9174f7bfaf2d2c8c1ee37cfdb462578 | |
parent | f3a642710989c3f47d5c2131efd69e3dbfedc336 (diff) | |
download | Nim-1d19cd660f39b9e76005b849ae1f7ca966278438.tar.gz |
fix #17458 tnetconnect.nim flaky (#17459)
* fix tests * fix #17458
-rw-r--r-- | tests/stdlib/tnetconnect.nim | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/tests/stdlib/tnetconnect.nim b/tests/stdlib/tnetconnect.nim index e27499651..b74545710 100644 --- a/tests/stdlib/tnetconnect.nim +++ b/tests/stdlib/tnetconnect.nim @@ -1,22 +1,26 @@ discard """ - cmd: "nim c -r -d:ssl $file" - exitcode: 0 + matrix: "-d:ssl" """ import std/net +from std/strutils import `%` -# Issue 15215 - https://github.com/nim-lang/Nim/issues/15215 +# bug #15215 proc test() = - var - ctx = newContext() - socket = newSocket() + let ctx = newContext() - wrapSocket(ctx, socket) + proc fn(url: string) = + let socket = newSocket() + defer: close(socket) + connect(socket, url, Port(443), 5000) # typically 20 could be enough + send(socket, "GET / HTTP/1.0\nHost: $#\nConnection: close\n\n" % [url]) + wrapSocket(ctx, socket) - connect(socket, "www.nim-lang.org", Port(443), 5000) - - send(socket, "GET / HTTP/1.0\nHost: www.nim-lang.org\nConnection: close\n\n") - - close(socket) + # trying 2 sites makes it more resilent: refs #17458 this could give: + # Error: unhandled exception: Call to 'connect' timed out. [TimeoutError] + try: + fn("www.nim-lang.org") + except TimeoutError: + fn("www.google.com") test() |