summaryrefslogtreecommitdiffstats
path: root/tests/socket.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/socket.test')
-rw-r--r--tests/socket.test37
1 files changed, 30 insertions, 7 deletions
diff --git a/tests/socket.test b/tests/socket.test
index dd57a3d..b121022 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -71,6 +71,23 @@ testConstraint exec [llength [info commands exec]]
# from 49152 through 65535.
proc randport {} { expr {int(rand()*16383+49152)} }
+# 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
+# up to 200ms for a packet sent to localhost to arrive. We're measuring this
+# here, so that OSes that don't have this problem can
+set server [socket -server {apply {{s a p} {set ::s1 $s}}} 0]
+set s2 [socket localhost [lindex [fconfigure $server -sockname] 2]]
+vwait s1; close $server
+fconfigure $s1 -buffering line
+fconfigure $s2 -buffering line
+set t1 [clock milliseconds]
+puts $s2 test1; gets $s1
+puts $s2 test2; gets $s1
+close $s1; close $s2
+set t2 [clock milliseconds]
+set latency [expr {$t2-$t1}]
+unset t1 t2 s1 s2 server
+
# If remoteServerIP or remoteServerPort are not set, check in the environment
# variables for externally set values.
#
@@ -584,7 +601,7 @@ test socket_$af-2.11 {detecting new data} -constraints [list socket supported_$a
fconfigure $sock -blocking 1
puts $s2 two
flush $s2
- after idle {set x 1}
+ after $latency {set x 1}; # NetBSD fails here if we do [after idle]
vwait x
fconfigure $sock -blocking 0
lappend result c:[gets $sock]
@@ -1713,12 +1730,14 @@ test socket-14.0 {[socket -async] when server only listens on one address family
set port [lindex [fconfigure $server -sockname] 2]
} -body {
set client [socket -async localhost $port]
- after 1000 {set x [fconfigure $client -error]}
+ set after [after 1000 {set x [fconfigure $client -error]}]
vwait x
set x
} -cleanup {
+ after cancel $after
close $server
close $client
+ unset x
} -result ok
test socket-14.1 {[socket -async] fileevent while still connecting} \
-constraints [list socket supported_any] \
@@ -1727,13 +1746,15 @@ test socket-14.1 {[socket -async] fileevent while still connecting} \
global x
puts $s bye
close $s
- set x ok
+ lappend x ok
}
- set server [socket -server accept -myaddr 127.0.0.1 2222]
+ set server [socket -server accept -myaddr 127.0.0.1 0]
set port [lindex [fconfigure $server -sockname] 2]
} -body {
set client [socket -async localhost $port]
- fileevent $client readable {lappend x [fconfigure $client -error]}
+ fileevent $client writable {
+ lappend x [expr {[fconfigure $client -error] eq ""}]
+ }
set after [after 1000 {set x timeout}]
vwait x
vwait x
@@ -1742,18 +1763,20 @@ test socket-14.1 {[socket -async] fileevent while still connecting} \
after cancel $after
close $server
close $client
- } -result {ok {}}
+ unset x
+ } -result {ok 1}
test socket-14.2 {[socket -async] fileevent connection refused} \
-constraints [list socket supported_any] \
-body {
set client [socket -async localhost 0]
- fileevent $client readable {set x [fconfigure $client -error]}
+ fileevent $client writable {set x [fconfigure $client -error]}
set after [after 1000 {set x timeout}]
vwait x
set x
} -cleanup {
after cancel $after
close $client
+ unset x
} -result "connection refused"
::tcltest::cleanupTests