Markdown
[ZOOM-Perl-moved-to-github.git] / archive / check_for_server_availability.patch
1 diff -ur Net-Z3950-ZOOM-1.24/t/16-packages.t Net-Z3950-ZOOM-1.24-networkcheck/t/16-packages.t
2 --- Net-Z3950-ZOOM-1.24/t/16-packages.t 2006-04-12 07:30:09.000000000 -0500
3 +++ Net-Z3950-ZOOM-1.24-networkcheck/t/16-packages.t    2008-09-12 09:29:21.000000000 -0500
4 @@ -14,15 +14,23 @@
5  
6  use strict;
7  use warnings;
8 -use Test::More tests => 40;
9 +use Test::More;
10  
11 -BEGIN { use_ok('Net::Z3950::ZOOM') };
12 +use Net::Z3950::ZOOM;
13  
14 +my $number_of_tests = 39;
15  
16  # We will create, and destroy, a new database with a random name
17  my $host = "test.indexdata.com:2118";
18  my $dbname = join("", map { chr(ord("a") + int(rand(26))) } 1..10);
19  
20 +# check to see if the server is unreachable. If so, we skip these tests
21 +if ( server_reachable( $host ) ) {
22 +    plan tests => $number_of_tests;
23 +} else {
24 +    plan skip_all => "host '$host' is unreachable. Network problem?";
25 +}
26 +
27  # Connect anonymously, and expect this to fail
28  my $conn = makeconn($host, undef, undef, 1011);
29  
30 @@ -191,3 +199,32 @@
31  
32      return $text;
33  }
34 +
35 +=head2 server_reachable
36 +
37 +returns true if the server is reachable.
38 +
39 +pass in the hostname or hostname:port string.
40 +
41 +returns 1 if reachable
42 +returns undef if not.
43 +
44 +=cut
45 +
46 +sub server_reachable {
47 +    my($host) = @_;
48 +    
49 +    # connection_timeout errorcode
50 +    my $connection_timeout = 10007;
51 +
52 +    my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
53 +
54 +    my $conn = Net::Z3950::ZOOM::connection_create( Net::Z3950::ZOOM::options_create() );
55 +    $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
56 +    return if $errcode;
57 +    
58 +    Net::Z3950::ZOOM::connection_connect($conn, $host, 0);
59 +    $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
60 +    return if ( $errcode == $connection_timeout );
61 +    return 1;
62 +}
63 diff -ur Net-Z3950-ZOOM-1.24/t/26-packages.t Net-Z3950-ZOOM-1.24-networkcheck/t/26-packages.t
64 --- Net-Z3950-ZOOM-1.24/t/26-packages.t 2006-06-07 04:58:56.000000000 -0500
65 +++ Net-Z3950-ZOOM-1.24-networkcheck/t/26-packages.t    2008-09-12 09:11:45.000000000 -0500
66 @@ -5,15 +5,23 @@
67  
68  use strict;
69  use warnings;
70 -use Test::More tests => 40;
71 +use Test::More;
72  
73 -BEGIN { use_ok('ZOOM') };
74 +use ZOOM;
75  
76 +my $number_of_tests = 39;
77  
78  # We will create, and destroy, a new database with a random name
79  my $host = "test.indexdata.com:2118";
80  my $dbname = join("", map { chr(ord("a") + int(rand(26))) } 1..10);
81  
82 +# check to see if the server is unreachable. If so, we skip these tests
83 +if ( server_reachable( $host ) ) {
84 +    plan tests => $number_of_tests;
85 +} else {
86 +    plan skip_all => "host '$host' is unreachable. Network problem?";
87 +}
88 +
89  # Connect anonymously, and expect this to fail
90  my $conn = makeconn($host, undef, undef, 1011);
91  
92 @@ -192,6 +200,24 @@
93      }
94  }
95  
96 +sub server_reachable {
97 +    my($host) = @_;
98 +
99 +    # connection_timeout errorcode
100 +    my $connection_timeout = 10007;
101 +
102 +    my $options = new ZOOM::Options();
103 +
104 +    my $conn;
105 +    eval { $conn = create ZOOM::Connection($options) };
106 +    return unless !$@ eq "unconnected connection object created";
107 +
108 +    eval { $conn->connect($host, 0) };
109 +    my($errcode, $errmsg, $addinfo) = maybe_error($@);
110 +    return if ( $errcode == $connection_timeout );
111 +    return 1;
112 +}
113 +
114  
115  # To investigate the set of databases created, use Explain Classic:
116  #