Ancient
view release on metacpan or search on metacpan
t/2039-doubly-deadlock.t view on Meta::CPAN
ok($ok, 'Deeply nested doubly destruction completed without deadlock');
};
# Test 3: Many operations in sequence
subtest 'No deadlock with many sequential operations' => sub {
plan tests => 1;
my $ok = with_timeout(5, sub {
my $list = doubly->new();
for my $i (1..1000) {
$list->add("item_$i");
$list->length;
$list->start;
$list->end;
if ($i % 10 == 0) {
$list->remove_from_start;
}
}
}, 'many sequential operations');
ok($ok, 'Many sequential operations completed without deadlock');
};
# Test 4: Callback during find (releases and reacquires lock)
subtest 'No deadlock during find callback' => sub {
plan tests => 1;
my $ok = with_timeout(5, sub {
my $list = doubly->new();
$list->bulk_add(1..100);
my $found = $list->find(sub {
my ($val) = @_;
# Simulate some work in callback
my $x = 0;
$x++ for 1..100;
return $val == 50;
});
}, 'find callback');
ok($ok, 'Find callback completed without deadlock');
};
# Test 5: Callback during insert (releases and reacquires lock)
subtest 'No deadlock during insert callback' => sub {
plan tests => 1;
my $ok = with_timeout(5, sub {
my $list = doubly->new();
$list->bulk_add(1, 3, 5, 7, 9);
# Insert 2 before the first element > 2
$list->insert(sub { $_[0] > 2 }, 2);
}, 'insert callback');
ok($ok, 'Insert callback completed without deadlock');
};
# Test 6: Mixed nested and callbacks
subtest 'No deadlock with nested objects in find' => sub {
plan tests => 1;
my $ok = with_timeout(5, sub {
my $list = doubly->new();
for my $i (1..10) {
my $inner = doubly->new();
$inner->add({ id => $i, name => "item_$i" });
$list->add($inner);
}
# Find a nested list and access its data
my $found = $list->find(sub {
my ($inner) = @_;
return ref($inner) eq 'doubly' && $inner->data->{id} == 5;
});
}, 'nested objects in find');
ok($ok, 'Nested objects in find completed without deadlock');
};
# Test 7: Explicit destroy followed by operations
subtest 'No issues after explicit destroy' => sub {
plan tests => 2;
my $ok = with_timeout(5, sub {
my $list = doubly->new();
$list->bulk_add(1..10);
$list->destroy;
# Operations on destroyed list should just return undef/0
my $len = $list->length;
is($len, 0, 'length is 0 after destroy');
}, 'explicit destroy');
ok($ok, 'Explicit destroy completed without deadlock');
};
# Test 8: Rapid create/destroy cycles
subtest 'No deadlock with rapid create/destroy cycles' => sub {
plan tests => 1;
my $ok = with_timeout(5, sub {
for my $i (1..100) {
my $list = doubly->new();
$list->add("item");
$list->destroy;
}
}, 'rapid create/destroy');
ok($ok, 'Rapid create/destroy cycles completed without deadlock');
};
done_testing();
( run in 0.412 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )