Subject: | 172.29.249.249 might pass |
e.g. when it is part of a VPN or other reasons beyond the control of the user.
I passed the tests using 10.20.30.40, so I suggest something like the attached.
a$ make test
Test Summary Report
-------------------
t/200_ping_tcp.t (Wstat: 256 Tests: 13 Failed: 1)
Failed test: 7
Non-zero exit status: 1
t/400_ping_syn.t (Wstat: 256 Tests: 14 Failed: 1)
Failed test: 11
Non-zero exit status: 1
Files=23, Tests=140, 14 wallclock secs ( 0.07 usr 0.02 sys + 1.58 cusr 0.23 csys = 1.90 CPU)
Result: FAIL
Failed 2/23 test programs. 2/140 subtests failed.
b$ env NET_PING_FAIL_IP=10.20.30.40 make test
All tests successful.
Files=23, Tests=140, 52 wallclock secs ( 0.07 usr 0.02 sys + 1.37 cusr 0.15 csys = 1.61 CPU)
Result: PASS
Subject: | Net-Ping.diff |
diff -purd a/t/190_alarm.t b/t/190_alarm.t
--- a/t/190_alarm.t 2016-09-15 10:57:50.000000000 +0200
+++ b/t/190_alarm.t 2018-08-06 14:30:55.964734987 +0200
@@ -28,6 +28,9 @@ use strict;
use Test::More tests => 6;
BEGIN {use_ok 'Net::Ping'};
+# Hopefully this is never a routeable host
+my $fail_ip = $ENV{NET_PING_FAIL_IP} || "172.29.249.249";
+
eval {
my $timeout = 11;
@@ -42,7 +45,7 @@ eval {
my $ping = Net::Ping->new("tcp", 2);
# It does not matter if alive or not
$ping->ping("127.0.0.1");
- $ping->ping("172.29.249.249");
+ $ping->ping($fail_ip);
die "alarm failed" if time > $start + $timeout + 1;
}
};
diff -purd a/t/200_ping_tcp.t b/t/200_ping_tcp.t
--- a/t/200_ping_tcp.t 2018-06-17 17:57:18.000000000 +0200
+++ b/t/200_ping_tcp.t 2018-08-06 14:31:08.160860615 +0200
@@ -17,6 +17,9 @@ BEGIN {
}
}
+# Hopefully this is never a routeable host
+my $fail_ip = $ENV{NET_PING_FAIL_IP} || "172.29.249.249";
+
# Remote network test using tcp protocol.
#
# NOTE:
@@ -50,8 +53,7 @@ isnt($p->{port_num} = (getservbyname("ht
isnt($p->ping("localhost"), 0, 'Test localhost on the web port');
-# Hopefully this is never a routeable host
-is($p->ping("172.29.249.249"), 0, "Can't reach 172.29.249.249");
+is($p->ping($fail_ip), 0, "Can't reach $fail_ip");
# Test a few remote servers
# Hopefully they are up when the tests are run.
diff -purd a/t/400_ping_syn.t b/t/400_ping_syn.t
--- a/t/400_ping_syn.t 2018-06-17 17:57:18.000000000 +0200
+++ b/t/400_ping_syn.t 2018-08-06 14:31:27.733062215 +0200
@@ -32,10 +32,12 @@ BEGIN {
#
# $ PERL_CORE=1 make test
+# Hopefully this is never a routeable host
+my $fail_ip = $ENV{NET_PING_FAIL_IP} || "172.29.249.249";
+
# Try a few remote servers
my %webs = (
- # Hopefully this is never a routeable host
- "172.29.249.249" => 0,
+ $fail_ip => 0,
# Hopefully all these web ports are open
"yahoo.com." => 1,
diff -purd a/t/410_syn_host.t b/t/410_syn_host.t
--- a/t/410_syn_host.t 2017-01-19 07:34:30.000000000 +0100
+++ b/t/410_syn_host.t 2018-08-06 14:39:03.377753571 +0200
@@ -36,9 +36,11 @@ BEGIN {
# Try a few remote servers
my %webs;
BEGIN {
- %webs = (
# Hopefully this is never a routeable host
- "172.29.249.249" => 0,
+ my $fail_ip = $ENV{NET_PING_FAIL_IP} || "172.29.249.249";
+
+ %webs = (
+ $fail_ip => 0,
# Hopefully all these web ports are open
"www.google.com." => 1,
diff -purd a/t/420_ping_syn_port.t b/t/420_ping_syn_port.t
--- a/t/420_ping_syn_port.t 2017-11-26 18:56:42.000000000 +0100
+++ b/t/420_ping_syn_port.t 2018-08-06 14:31:18.356965639 +0200
@@ -33,11 +33,13 @@ BEGIN {
#
# $ PERL_CORE=1 make test
+# Hopefully this is never a routeable host
+my $fail_ip = $ENV{NET_PING_FAIL_IP} || "172.29.249.249";
+
# Try a few remote servers
my %webs;
my @hosts = (
- # Hopefully this is never a routeable host
- "172.29.249.249",
+ $fail_ip,
# Hopefully all these http and https ports are open
"www.google.com",
@@ -91,11 +93,11 @@ while (my @r = $p->ack()) {
}
Alarm(0);
-# 172.29.249.249 should not be reachable
+# $fail_ip should not be reachable
is keys %contacted, 2,
'2 servers did not acknowledge our ping'
or diag sort keys %contacted;
delete $contacted{$_}
- foreach ('172.29.249.249:80','172.29.249.249:443', 'www.about.com:443');
+ foreach ("$fail_ip:80","$fail_ip:443", 'www.about.com:443');
is keys %contacted, 0,
'The servers that did not acknowledge our ping were correct';