Algorithm-EventsPerSecond
view release on metacpan or search on metacpan
t/sukkal-protocol.t view on Meta::CPAN
#!perl
# Protocol edge cases: input fragmentation and reassembly, line
# framing, and the validation boundaries of the wire protocol.
use 5.006;
use strict;
use warnings;
use Test::More;
BEGIN {
plan skip_all => 'unix domain sockets and fork required'
if $^O eq 'MSWin32';
t/sukkal-protocol.t view on Meta::CPAN
$SIG{PIPE} = 'IGNORE';
alarm 120; # watchdog: a hung daemon must fail the test, not the harness
my $d = spawn_daemon( window => 5, max_key_length => 10 );
my $sock = connect_daemon($d);
#
# a command split across two writes is reassembled from the read buffer
#
print $sock 'MARK fr';
sleep 0.25; # let the daemon read the fragment on its own
print $sock "ag 3\nCOUNT frag\n";
is( read_line($sock), 'OK 3', 'command fragmented across writes is reassembled' );
#
# one byte per write: reassembly across many reads
#
for my $byte ( split //, "COUNT frag\n" ) {
print $sock $byte;
sleep 0.02;
}
is( read_line($sock), 'OK 3', 'command dribbled a byte at a time is reassembled' );
#
# blank and whitespace-only lines are skipped without a reply;
# commands are case-insensitive and tolerate CRLF
#
print $sock "\n \nping\r\n";
( run in 0.890 second using v1.01-cache-2.11-cpan-b16cb0d3907 )