Data-RingBuffer-Shared

 view release on metacpan or  search on metacpan

t/04-edges.t  view on Meta::CPAN

    is $r->count, 0;
    $r->write(1);
    is $r->latest(0), 1;
    $r->write(2);
    is $r->latest(0), 2, 'overwrote previous';
    is $r->count, 2, 'count tracks total writes';
    my $stats = $r->stats;
    is $stats->{overwrites}, 1, 'one overwrite tracked';
}

# --- all-null / all-0xFF binary (F64 — NaN/Inf edges) ---
{
    my $r = Data::RingBuffer::Shared::F64->new(undef, 8);
    $r->write(0.0);
    $r->write("Inf" + 0);
    $r->write("-Inf" + 0);
    $r->write("NaN" + 0);
    is $r->latest(3), 0.0;
    ok $r->latest(2) > 0 && ($r->latest(2) == $r->latest(2) + 1), 'positive inf';
    ok $r->latest(1) < 0 && ($r->latest(1) == $r->latest(1) - 1), 'negative inf';
    my $nan = $r->latest(0);
    ok $nan != $nan, 'NaN != NaN';
}

# --- odd (non-power-of-2) capacity ---
{
    my $r = Data::RingBuffer::Shared::Int->new(undef, 17);
    $r->write($_) for 1..50;
    is $r->count, 50, 'count tracks total';
    is $r->size, 17, 'size caps at capacity';
    # The last 17 should be 34..50
    my @last = map { $r->latest($_) } 0..16;

xt/timeout_validation.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use POSIX qw(_exit);
use Time::HiRes qw(time);
use Data::RingBuffer::Shared;

plan skip_all => 'AUTHOR_TESTING not set' unless $ENV{AUTHOR_TESTING};

# Boundary timeouts: negative, +Inf, NaN. None should crash; results
# should match documented behavior or croak cleanly.

my $h = Data::RingBuffer::Shared::Int->new(undef, 4);

# Run each timeout in a child to detect signal-death.
sub run_child {
    my ($label, $code) = @_;
    my $pid = fork // die;
    if ($pid == 0) {
        eval { $code->() };

xt/timeout_validation.t  view on Meta::CPAN

    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, -1.0) });
isnt $r1, 'signal_11', "negative timeout: no SIGSEGV (got $r1)";
isnt $r1, 'signal_6',  "negative timeout: no SIGABRT (got $r1)";

# +Infinity: same as negative, may block forever
my $r2 = run_child('inf timeout',
    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, "Inf"+0) });
isnt $r2, 'signal_11', "inf timeout: no SIGSEGV (got $r2)";
isnt $r2, 'signal_6',  "inf timeout: no SIGABRT (got $r2)";

# NaN: implementation-defined, must not crash
my $r3 = run_child('nan timeout',
    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, "NaN"+0) });
isnt $r3, 'signal_11', "NaN timeout: no SIGSEGV (got $r3)";
isnt $r3, 'signal_6',  "NaN timeout: no SIGABRT (got $r3)";

done_testing;



( run in 0.558 second using v1.01-cache-2.11-cpan-39bf76dae61 )