3 # This file is part of POE::Component::Client::MPD.
4 # Copyright (c) 2007-2008 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
15 use POE qw{ Component::Client::MPD::Connection };
17 use Test::More tests => 4;
19 Readonly my $ALIAS => 'tester';
23 my $id = POE::Session->create(
25 _start => \&_onpriv_start,
26 mpd_connect_error_retriable => \&_onprot_mpd_connect_error_retriable,
27 mpd_connect_error_fatal => \&_onprot_mpd_connect_error_fatal,
30 my $conn = POE::Component::Client::MPD::Connection->spawn( {
35 max_retries => $max_retries,
43 my ($k, $h) = @_[KERNEL, HEAP];
44 $k->alias_set($ALIAS); # increment refcount
48 sub _onprot_mpd_connect_error_retriable {
49 my ($k, $h, $errstr) = @_[KERNEL, HEAP, ARG0];
50 like($errstr, qr/^connect: \(\d+\) /, 'retriable error trapped');
54 sub _onprot_mpd_connect_error_fatal {
55 my ($k, $h, $errstr) = @_[KERNEL, HEAP, ARG0];
58 is($h->{count}, $max_retries-1, 'retriable errors are tried again $max_retries times');
59 like($errstr, qr/^Too many failed attempts!/, 'too many errors lead to fatal error');
62 $k->post($conn, 'disconnect');
63 $k->alias_remove($ALIAS); # decrement refcount