ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-RPC/t/03_connfail.t
Revision: 1.1
Committed: Tue Mar 26 04:19:31 2019 UTC (7 years, 6 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_24
Log Message:
1.24

File Contents

# User Rev Content
1 root 1.1 # connection failure test, written by Johan Finnved <johan@finnved.se>
2    
3     $| = 1;
4     print "1..5\n";
5    
6     use AnyEvent;
7     use AnyEvent::Fork::RPC;
8    
9     print "ok 1\n";
10    
11     my $done = AE::cv;
12    
13     # Test behavior when AnyEvent::Fork::Remote connection fails
14     # without creating dependency to AnyEvent::Fork::Remote
15    
16     # Equivalent of
17     # my $rpc = AnyEvent::Fork::Remote
18     # ->new_execp ("ssh", "ssh", 'host-down.example.com', "perl")
19     # ->AnyEvent::Fork::RPC::run ("run",
20    
21     my $rpc = AnyEvent::Fork::Remote::Dummy
22     ->new
23     ->AnyEvent::Fork::RPC::run ("run",
24     async => 1,
25     on_error => sub { $done->send ("ok 5 - expected on_error\n") },
26     on_event => sub { print "on_event $_[0]\n" },
27     on_destroy => sub { $done->send ("not ok 5 - on_destroy\n") },
28     );
29    
30     print "ok 2\n";
31    
32     $rpc->(3, sub { print $_[0] });
33    
34     print "ok 3\n";
35    
36     undef $rpc;
37    
38     print "ok 4\n";
39    
40     my $w = AE::timer 5, 0, sub {$done->send("not ok 5 - timeout connection error not reported\n") };
41    
42     print $done->recv;
43    
44     package AnyEvent::Fork::Remote::Dummy;
45    
46     sub new { my $a ; bless \$a }
47    
48     sub require { $_[0] }
49     sub send_arg { $_[0] }
50    
51     # Report connection error by not returning fh
52     # just like AnyEvent::Fork::Remote
53     sub run {
54     my ($self, $remoteMethod, $connectCb) = @_;
55     AE::postpone { $connectCb->() };
56     $self;
57     }
58