summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-04-11 18:10:09 (GMT)
committersebres <sebres@users.sourceforge.net>2017-04-11 18:10:09 (GMT)
commitae427aa306ea9f72ad3974284d1c783282f6fe65 (patch)
tree143ab91453d4f42cb52535e76d356ddb22de3e45
parent992af585dd13c64af68e50f9cad503afb6f0b1ed (diff)
downloadtcl-ae427aa306ea9f72ad3974284d1c783282f6fe65.zip
tcl-ae427aa306ea9f72ad3974284d1c783282f6fe65.tar.gz
tcl-ae427aa306ea9f72ad3974284d1c783282f6fe65.tar.bz2
improves robustness of the socket tests against busy random ports (fixed sporadic errors "already in use")
-rw-r--r--tests/socket.test17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/socket.test b/tests/socket.test
index d43c41c..a3e5704 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -69,7 +69,22 @@ testConstraint exec [llength [info commands exec]]
# Produce a random port number in the Dynamic/Private range
# from 49152 through 65535.
-proc randport {} { expr {int(rand()*16383+49152)} }
+proc randport {} {
+ # firstly try dynamic port via server-socket(0):
+ set port 0x7fffffff
+ catch {
+ set port [lindex [fconfigure [set s [socket -server {} 0]] -sockname] 2]
+ close $s
+ }
+ while {[catch {
+ close [socket -server {} $port]
+ } msg]} {
+ if {[incr i] > 1000} {return -code error "too many iterations to get free random port: $msg"}
+ # try random port:
+ set port [expr {int(rand()*16383+49152)}]
+ }
+ return $port
+}
# Test the latency of tcp connections over the loopback interface. Some OSes
# (e.g. NetBSD) seem to use the Nagle algorithm and delayed ACKs, so it takes