1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
BEGIN {
eval { require Test::MemoryGrowth; } or
plan skip_all => "No Test::MemoryGrowth";
}
use Test::MemoryGrowth;
use Future;
use Future::AsyncAwait qw( :experimental(cancel) );
async sub identity
{
await $_[0];
}
sub code
{
my $f1 = Future->new;
my $fret = identity( $f1 );
$f1->done;
$fret->get;
}
no_growth \&code,
calls => 10000,
'async/await does not grow memory';
sub abandoned
{
my $f1 = Future->new;
my $fret = (async sub {
local $@;
foreach my $i ( 1, 2, 3 ) {
await $f1;
}
})->();
undef $fret;
undef $f1;
}
no_growth \&abandoned,
calls => 10000,
'abandoned async sub does not grow memory';
sub precancelled
{
my $f1 = Future->new;
my $fret = (async sub {
CANCEL { }
await $f1;
})->();
$f1->done;
$fret->get;
}
no_growth \&precancelled,
calls => 10000,
'precancellation does not grow memory';
# RT142222
{
my $ftick;
my $floop = (async sub {
while(1) {
await ( $ftick = Future->new );
}
})->();
no_growth sub {
my $f = $ftick;
undef $ftick;
$f->done;
}, calls => 10000,
'loop later does not grow memory';
}
done_testing;
|