summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormax <max@tclers.tk>2017-04-05 14:47:45 (GMT)
committermax <max@tclers.tk>2017-04-05 14:47:45 (GMT)
commit4f20b26224ed27d2a75607416198e615bee7e128 (patch)
tree57abcc29f7295ecf5cd79a264ec872474b0813e0
parent42f3b8e10cbe3342ebc2ca136374b4c5377dc54c (diff)
downloadtcl-4f20b26224ed27d2a75607416198e615bee7e128.zip
tcl-4f20b26224ed27d2a75607416198e615bee7e128.tar.gz
tcl-4f20b26224ed27d2a75607416198e615bee7e128.tar.bz2
Use a random unused port for the dummy http server to avoid conflicts
with local services running on port 8010.
-rw-r--r--tests/http.test8
-rw-r--r--tests/httpd7
-rw-r--r--tests/httpold.test6
3 files changed, 11 insertions, 10 deletions
diff --git a/tests/http.test b/tests/http.test
index 12ad475..75c963d 100644
--- a/tests/http.test
+++ b/tests/http.test
@@ -36,7 +36,6 @@ proc bgerror {args} {
puts stderr $errorInfo
}
-set port 8010
set bindata "This is binary data\x0d\x0amore\x0dmore\x0amore\x00null"
catch {unset data}
@@ -55,9 +54,8 @@ catch {package require Thread 2.7-}
if {[catch {package present Thread}] == 0 && [file exists $httpdFile]} {
set httpthread [thread::create -preserved]
thread::send $httpthread [list source $httpdFile]
- thread::send $httpthread [list set port $port]
thread::send $httpthread [list set bindata $bindata]
- thread::send $httpthread {httpd_init $port}
+ thread::send $httpthread {httpd_init 0; set port} port
puts "Running httpd in thread $httpthread"
} else {
if {![file exists $httpdFile]} {
@@ -69,10 +67,8 @@ if {[catch {package present Thread}] == 0 && [file exists $httpdFile]} {
# Let the OS pick the port; that's much more flexible
if {[catch {httpd_init 0} listen]} {
puts "Cannot start http server, http test skipped"
- unset port
+ catch {unset port}
return
- } else {
- set port [lindex [fconfigure $listen -sockname] 2]
}
}
diff --git a/tests/httpd b/tests/httpd
index 40e10df..f15d71b 100644
--- a/tests/httpd
+++ b/tests/httpd
@@ -11,7 +11,12 @@
#set httpLog 1
proc httpd_init {{port 8015}} {
- socket -server httpdAccept $port
+ set s [socket -server httpdAccept $port]
+ # Save the actual port number in a global variable.
+ # This is important when we're called with port 0
+ # for picking an unused port at random.
+ set ::port [lindex [chan configure $s -sockname] 2]
+ return $s
}
proc httpd_log {args} {
global httpLog
diff --git a/tests/httpold.test b/tests/httpold.test
index 5995bed..ab26613 100644
--- a/tests/httpold.test
+++ b/tests/httpold.test
@@ -1,3 +1,4 @@
+# -*- tcl -*-
# Commands covered: http_config, http_get, http_wait, http_reset
#
# This file contains a collection of tests for the http script library.
@@ -41,10 +42,9 @@ catch {unset data}
##
source [file join [file dirname [info script]] httpd]
-set port 8010
-if [catch {httpd_init $port} listen] {
+if [catch {httpd_init 0} listen] {
puts "Cannot start http server, http test skipped"
- unset port
+ catch {unset port}
::tcltest::cleanupTests
return
}