summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/socket.test67
1 files changed, 60 insertions, 7 deletions
diff --git a/tests/socket.test b/tests/socket.test
index 7f5c5c2..363f141 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -1751,21 +1751,23 @@ test socket-14.1 {[socket -async] fileevent while still connecting} \
}
set server [socket -server accept -myaddr 127.0.0.1 0]
set port [lindex [fconfigure $server -sockname] 2]
+ set x ""
} -body {
set client [socket -async localhost $port]
fileevent $client writable {
- lappend x [expr {[fconfigure $client -error] eq ""}]
+ lappend x [fconfigure $client -error]
}
- set after [after 1000 {set x timeout}]
- vwait x
- vwait x
- set x
+ set after [after 1000 {lappend x timeout}]
+ while {[llength $x] < 2 && "timeout" ni $x} {
+ vwait x
+ }
+ lsort $x; # we only want to see both events, the order doesn't matter
} -cleanup {
after cancel $after
close $server
close $client
unset x
- } -result {ok 1}
+ } -result {{} ok}
test socket-14.2 {[socket -async] fileevent connection refused} \
-constraints [list socket supported_any] \
-body {
@@ -1782,7 +1784,58 @@ test socket-14.2 {[socket -async] fileevent connection refused} \
close $client
unset x
} -result "connection refused"
-
+test socket-14.3 {[socket -async] fileevent host unreachable} \
+ -constraints [list socket supported_any] \
+ -body {
+ # address from rfc5737
+ set client [socket -async 192.0.2.42 [randport]]
+ fileevent $client writable {set x [fconfigure $client -error]}
+ set after [after 5000 {set x timeout}]
+ vwait x
+ if {$x eq "timeout"} {
+ append x ": [fconfigure $client -error]"
+ }
+ set x
+ } -cleanup {
+ after cancel $after
+ close $client
+ unset x
+ } -result "host is unreachable"
+test socket-14.4 {[socket -async] and both, readdable and writable fileevents} \
+ -constraints [list socket supported_any] \
+ -setup {
+ proc accept {s a p} {
+ puts $s bye
+ close $s
+ }
+ set server [socket -server accept -myaddr 127.0.0.1 0]
+ set port [lindex [fconfigure $server -sockname] 2]
+ set x ""
+ } -body {
+ set client [socket -async localhost $port]
+ fileevent $client writable {
+ lappend x [fconfigure $client -error]
+ fileevent $client writable {}
+ }
+ fileevent $client readable {lappend x [gets $client]}
+ set after [after 1000 {lappend x timeout}]
+ while {[llength $x] < 2 && "timeout" ni $x} {
+ vwait x
+ }
+ lsort $x
+ } -cleanup {
+ after cancel $after
+ close $client
+ close $server
+ } -result {{} bye}
+test socket-14.5 {[socket -async] which fails before any connect() can be made} \
+ -constraints [list socket supported_any] \
+ -body {
+ # addresses from rfc5737
+ socket -async -myaddr 192.0.2.42 198.51.100.42 [randport]
+ } \
+ -returnCodes 1 \
+ -result {couldn't open socket: cannot assign requested address}
::tcltest::cleanupTests
flush stdout
return