summary refs log tree commit diff stats
path: root/tests/stdlib/tnetconnect.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stdlib/tnetconnect.nim')
-rw-r--r--tests/stdlib/tnetconnect.nim34
1 files changed, 21 insertions, 13 deletions
diff --git a/tests/stdlib/tnetconnect.nim b/tests/stdlib/tnetconnect.nim
index e27499651..ae654aed9 100644
--- a/tests/stdlib/tnetconnect.nim
+++ b/tests/stdlib/tnetconnect.nim
@@ -1,22 +1,30 @@
 discard """
-  cmd: "nim c -r -d:ssl $file"
-  exitcode: 0
+  disabled: "i386"
+  matrix: "-d:ssl"
 """
 
 import std/net
+from std/strutils import `%`
+from stdtest/testutils import enableRemoteNetworking
 
-# 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)
+  # trying 2 sites makes it more resilent: refs #17458 this could give:
+  # * Call to 'connect' timed out. [TimeoutError]
+  # * No route to host [OSError]
+  try:
+    fn("www.nim-lang.org")
+  except TimeoutError, OSError:
+    fn("www.google.com")
 
-  send(socket, "GET / HTTP/1.0\nHost: www.nim-lang.org\nConnection: close\n\n")
-
-  close(socket)
-
-test()
+when enableRemoteNetworking:
+  test()