Fluent-Logger
    
    
  
  
  
view release on metacpan or search on metacpan
t/02_unix_socket.t view on Meta::CPAN
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../";
use Test::More;
use Test::SharedFork;
use File::Temp qw/ tempdir /;
use t::Util qw/ streaming_decode_mp /;
use IO::Socket::UNIX;
use_ok "Fluent::Logger";
my $dir  = tempdir( CLEANUP => 1 );
my $sock = "$dir/test.sock";
note "socket: $sock";
my $pid = fork();
if ($pid == 0) {
t/02_unix_socket.t view on Meta::CPAN
    ok $logger->close;
}
elsif (defined $pid) {
    Test::SharedFork->parent;
    my $sock = IO::Socket::UNIX->new(
        Local  => $sock,
        Listen => 5,
    ) or die "Cannot open server socket: $!";
    while (my $cs = $sock->accept) {
        my $data = streaming_decode_mp($cs);
        note explain $data;
        isa_ok $data         => "ARRAY";
        is $data->[0]        => "test.debug";
        is_deeply $data->[2] => { foo => "bar" };
        last;
    }
    waitpid $pid, 0;
    done_testing;
} else {
    die "Cannot fork: $!";
use strict;
use FindBin;
use lib "$FindBin::Bin/../";
use Test::More;
use Test::SharedFork;
use File::Temp qw/ tempdir /;
use t::Util qw/ streaming_decode_mp /;
use Test::TCP();
use IO::Socket::INET;
use_ok "Fluent::Logger";
my $port = Test::TCP::empty_port;
note "port: $port";
my $pid = fork();
if ($pid == 0) {
}
elsif (defined $pid) {
    Test::SharedFork->parent;
    my $sock = IO::Socket::INET->new(
        LocalPort => $port,
        LocalAddr => "127.0.0.1",
        Listen    => 5,
    ) or die "Cannot open server socket: $!";
    while (my $cs = $sock->accept) {
        my $data = streaming_decode_mp($cs);
        note explain $data;
        isa_ok $data         => "ARRAY";
        is $data->[0]        => "test.debug";
        is_deeply $data->[2] => { foo => "bar" };
        last;
    }
    sleep 1;
    done_testing;
};
package t::Util;
use strict;
use warnings;
use File::Temp qw/ tempdir /;
use Path::Tiny qw/ path /;
use Test::TCP;
use version;
use Exporter 'import';
our $ENABLE_TEST_EVENT_TIME;
our @EXPORT_OK = qw/ streaming_decode_mp run_fluentd slurp_log $ENABLE_TEST_EVENT_TIME /;
sub streaming_decode_mp {
    my $sock   = shift;
    my $offset = 0;
    my $up     = Data::MessagePack::Unpacker->new;
    while( read($sock, my $buf, 1024) ) {
        $offset = $up->execute($buf, $offset);
        if ($up->is_finished) {
            return $up->data;
        }
    }
}
( run in 0.619 second using v1.01-cache-2.11-cpan-5dc5da66d9d )