From 7a5ccf05a158775ce039bad986d9655f4ede01c3 Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Thu, 16 May 2024 15:19:59 +0000 Subject: [PATCH] test: choose random port --- example.tcl | 2 +- tests.tcl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example.tcl b/example.tcl index b3b5b5a..7228ba4 100755 --- a/example.tcl +++ b/example.tcl @@ -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 diff --git a/tests.tcl b/tests.tcl index d45699a..f270e25 100755 --- a/tests.tcl +++ b/tests.tcl @@ -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] }]} { @@ -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!" } @@ -536,7 +536,7 @@ test example \
  • /template
  • /quit
  • } - 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 }