Skip to content

Commit 1d19cd6

Browse files
authored
fix #17458 tnetconnect.nim flaky (#17459)
* fix tests * fix #17458
1 parent f3a6427 commit 1d19cd6

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tests/stdlib/tnetconnect.nim

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
discard """
2-
cmd: "nim c -r -d:ssl $file"
3-
exitcode: 0
2+
matrix: "-d:ssl"
43
"""
54

65
import std/net
6+
from std/strutils import `%`
77

8-
# Issue 15215 - https://github.com/nim-lang/Nim/issues/15215
8+
# bug #15215
99
proc test() =
10-
var
11-
ctx = newContext()
12-
socket = newSocket()
10+
let ctx = newContext()
1311

14-
wrapSocket(ctx, socket)
12+
proc fn(url: string) =
13+
let socket = newSocket()
14+
defer: close(socket)
15+
connect(socket, url, Port(443), 5000) # typically 20 could be enough
16+
send(socket, "GET / HTTP/1.0\nHost: $#\nConnection: close\n\n" % [url])
17+
wrapSocket(ctx, socket)
1518

16-
connect(socket, "www.nim-lang.org", Port(443), 5000)
17-
18-
send(socket, "GET / HTTP/1.0\nHost: www.nim-lang.org\nConnection: close\n\n")
19-
20-
close(socket)
19+
# trying 2 sites makes it more resilent: refs #17458 this could give:
20+
# Error: unhandled exception: Call to 'connect' timed out. [TimeoutError]
21+
try:
22+
fn("www.nim-lang.org")
23+
except TimeoutError:
24+
fn("www.google.com")
2125

2226
test()

0 commit comments

Comments
 (0)