summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2016-11-03 09:37:02 +0100
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2016-11-03 09:37:02 +0100
commitb369d47038a075706f6dfe57ab2e1ebeea0e5bdf (patch)
treec2b4912cf1934397b814e4d8fd6ea6f8dd569c10 /test
parentb16852e23e1c477797bd7ce578a0f96bf341341c (diff)
Testsuite: move dynamic_socket to Exim::Runtest
Diffstat (limited to 'test')
-rw-r--r--test/lib/Exim/Runtest.pm17
-rwxr-xr-xtest/runtest12
-rw-r--r--test/t/00-basic.t8
3 files changed, 23 insertions, 14 deletions
diff --git a/test/lib/Exim/Runtest.pm b/test/lib/Exim/Runtest.pm
index 2ac9a61ee..1df2ea1a9 100644
--- a/test/lib/Exim/Runtest.pm
+++ b/test/lib/Exim/Runtest.pm
@@ -1,6 +1,7 @@
package Exim::Runtest;
use strict;
use warnings;
+use IO::Socket::INET;
use Carp;
use List::Util qw'shuffle';
@@ -22,7 +23,19 @@ sub mailgroup {
push @groups, $_ while defined($_ = getgrent);
endgrent;
return (shuffle @groups)[0];
-};
-
+}
+
+sub dynamic_socket {
+ my $socket;
+ for (my $port = 1024; $port < 65000; $port++) {
+ $socket = IO::Socket::INET->new(
+ LocalHost => '127.0.0.1',
+ LocalPort => $port,
+ Listen => 10,
+ ReuseAddr => 1,
+ ) and return $socket;
+ }
+ croak 'Can not allocate a free port.';
+}
1;
diff --git a/test/runtest b/test/runtest
index 78cd051d3..38047b1eb 100755
--- a/test/runtest
+++ b/test/runtest
@@ -21,7 +21,6 @@ use warnings;
use Errno;
use FileHandle;
-use IO::Socket::INET;
use Socket;
use Time::Local;
use Cwd;
@@ -3719,16 +3718,7 @@ foreach $test (@test_list)
if (/^no_stdout_check/) { $stdout_skip = 1; next; }
if (/^rmfiltertest/) { $rmfiltertest = 1; next; }
if (/^sortlog/) { $sortlog = 1; next; }
- if (/\bPORT_DYNAMIC\b/) {
- for (my $port = 1024; $port < 65000; $port++) {
- $dynamic_socket = IO::Socket::INET->new(
- LocalHost => '127.0.0.1',
- LocalPort => $port,
- Listen => 10,
- ReuseAddr => 1,
- ) and last;
- }
- }
+ if (/\bPORT_DYNAMIC\b/) { $dynamic_socket = Exim::Runtest::dynamic_socket(); next; }
}
# Reset to beginning of file for per test interpreting/processing
seek(SCRIPT, 0, 0);
diff --git a/test/t/00-basic.t b/test/t/00-basic.t
index a131b762f..3d5503a08 100644
--- a/test/t/00-basic.t
+++ b/test/t/00-basic.t
@@ -2,7 +2,7 @@ use Test::More;
use lib 'lib';
use_ok 'Exim::Runtest' or BAIL_OUT 'Can not load the module';
-can_ok 'Exim::Runtest', qw(mailgroup);
+can_ok 'Exim::Runtest', qw(mailgroup dynamic_socket);
subtest 'mailgroup' => sub {
my $group = getgrgid $(;
@@ -16,6 +16,12 @@ subtest 'mailgroup' => sub {
ok getgrnam($group) => 'got an existing group';
};
+subtest 'dynamic_socket' => sub {
+ ok my $socket = Exim::Runtest::dynamic_socket() => 'got a socket';
+ diag "got socket on port @{[$socket->sockport]}";
+ isa_ok $socket => 'IO::Socket::INET';
+ $socket->close;
+};
done_testing;