Skip to content

Commit

Permalink
test: choose random port
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed May 16, 2024
1 parent f2a9d5b commit d5c7db4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example.tcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env jimsh
# An HTTP server and web framework for Jim Tcl.
# Copyright (C) 2014, 2015, 2016 dbohdan.
# Copyright (C) 2014-2016 D. Bohdan.
# License: MIT
source arguments.tcl
source html.tcl
Expand Down
10 changes: 5 additions & 5 deletions tests.tcl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env jimsh
# Tests for the web framework and its modules.
# Copyright (c) 2014, 2015, 2016, 2018, 2019, 2020 D. Bohdan.
# Copyright (c) 2014-2016, 2018-2020, 2024 D. Bohdan.
# License: MIT

source testing.tcl
namespace import ::testing::*

proc client-socket {server port} {
# This code must run in Tcl 8.5.
# This code must run in Tcl 8.5-9.
if {[catch {
set ch [socket stream $server:$port]
}]} {
Expand Down Expand Up @@ -510,8 +510,8 @@ test example \
return $result
}

set port 8080
set url "http://localhost:$port"
set port [expr { 8000 + int(1000 * rand()) }]
set url http://localhost:$port
if {![catch {test-url $url}]} {
error "Can't test example: port $port taken!"
}
Expand All @@ -536,7 +536,7 @@ test example \
<li><a href="/template">/template</a></li>
<li><a href="/quit">/quit</a></li></ul></html>}

set handle [open [list | [info nameofexecutable] example.tcl -v 99]]
set handle [open [list | [info nameofexecutable] example.tcl -p $port -v 99]]
set pid [pid $handle]
# Wait until the server is ready to respond.
$handle readable { set ::ready 1 }
Expand Down

0 comments on commit d5c7db4

Please sign in to comment.