Skip to content

Commit 78d8bc4

Browse files
committed
runtests: use a per-runner random seed
Each runner needs a unique random seed to reduce the chance of port number collisions. The new scheme uses a consistent per-runner source of randomness which results in deterministic behaviour, as it did before. Ref: curl#10818
1 parent 4317c55 commit 78d8bc4

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

tests/globalconfig.pm

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ BEGIN {
5050
$proxy_address
5151
$PROXYIN
5252
$pwd
53+
$randseed
5354
$run_event_based
5455
$SERVERIN
5556
$srcdir
@@ -80,6 +81,7 @@ our $run_event_based; # run curl with --test-event to test the event API
8081
our $automakestyle; # use automake-like test status output format
8182
our $anyway; # continue anyway, even if a test fail
8283
our $CURLVERSION=""; # curl's reported version number
84+
our $randseed = 0; # random number seed
8385

8486
# paths
8587
our $pwd = getcwd(); # current working directory

tests/runner.pm

+7
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ sub runner_init {
168168
$ENV{'XDG_CONFIG_HOME'}=$ENV{'HOME'};
169169
$ENV{'COLUMNS'}=79; # screen width!
170170

171+
# Incorporate the $logdir into the random seed and re-seed the PRNG.
172+
# This gives each runner a unique yet consistent seed which provides
173+
# more unique port number selection in each runner, yet is deterministic
174+
# across runs.
175+
$randseed += unpack('%16C*', $logdir);
176+
srand $randseed;
177+
171178
# create pipes for communication with runner
172179
my ($thisrunnerr, $thiscontrollerw, $thiscontrollerr, $thisrunnerw);
173180
pipe $thisrunnerr, $thiscontrollerw;

tests/runtests.pl

-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ BEGIN
177177
my $postmortem; # display detailed info about failed tests
178178
my $run_disabled; # run the specific tests even if listed in DISABLED
179179
my $scrambleorder;
180-
my $randseed = 0;
181180
my $jobs = 0;
182181

183182
# Azure Pipelines specific variables

0 commit comments

Comments
 (0)