Debian Codegraph @

t/02max-items.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use v5.14;
4 use warnings;
5
6 use Test2::V0;
7
8 use Future;
9 use Future::Queue;
10
11 {
12 my $queue = Future::Queue->new( max_items => 5 );
13
14 $queue->push( $_ ) for 1 .. 5;
15
16 my $push_f = $queue->push( 6 );
17
18 ok( !$push_f->is_done, '$queue->push returned pending Future' );
19
20 my $shift_f = $queue->shift;
21
22 ok( $push_f->is_done, 'push future now done after shift' );
23 }
24
25 # RT151010
26 {
27 my $queue = Future::Queue->new( max_items => 5 );
28
29 my @pushf = map { $queue->push( $_ ) } 'a' .. 'q';
30
31 # Should not spinlock in deep recursion
32 my @shiftf = map { $queue->shift_atmost( 2 ) } 1 .. 9;
33
34 is( [ map { $_->state } @pushf ], [ ("done") x 17 ],
35 'all push futures completed' );
36 is( [ map { $_->state } @shiftf ], [ ("done") x 9 ],
37 'all shift futures completed' );
38 }
39
40 done_testing;