IPC-Run

 view release on metacpan or  search on metacpan

t/input_buffer_growth.t  view on Meta::CPAN

## Simulates the original bug scenario: user appends small chunks to $in
## on each pump_nb call.  With the fix, $in should stay bounded because
## the filter drains it in 65536-byte chunks.  Without the fix, $in would
## grow to the total data size before being flushed all at once.
{
    my ( $in, $out ) = ( '', '' );
    my $h = start( \@passthrough, \$in, \$out, timeout(30) );

    my $chunk_size   = 65536;
    my $user_chunk   = 1024;         # bytes added per iteration
    my $iterations   = 400;          # total = 400KB
    my $max_in_seen  = 0;

    for ( 1 .. $iterations ) {
        $in .= 'C' x $user_chunk;
        $h->pump_nb;
        my $cur = length($in);
        $max_in_seen = $cur if $cur > $max_in_seen;
    }

    $in = '';
    $h->finish;

    # With the fix, $in is drained in 65536-byte increments, so the maximum
    # observed $in size should stay well below the total data volume.
    # Allow generous slack for OS scheduling variation.
    my $total = $user_chunk * $iterations;
    cmp_ok( $max_in_seen, '<', $total,
        'GH#154: $in does not accumulate all data before flushing' );
}



( run in 1.728 second using v1.01-cache-2.11-cpan-71847e10f99 )