File: 07notifier-future.t

package info (click to toggle)
libio-async-perl 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,068 kB
  • ctags: 491
  • sloc: perl: 12,530; makefile: 8
file content (58 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Fatal;
use Test::Refcount;

use IO::Async::Notifier;
use Future;

my ( $err, $name, @detail );
my $notifier = IO::Async::Notifier->new(
   on_error => sub {
      ( undef, $err, $name, @detail ) = @_;
   },
);

# done
{
   my $f = Future->new;

   $notifier->adopt_future( $f );

   is_refcount( $f, 2, '$f has refcount 2 after ->adopt_future' );
   is_oneref( $notifier, '$notifier still has refcount 1 after ->adopt_future' );

   $f->done( "result" );

   is_refcount( $f, 1, '$f has refcount 1 after $f->done' );
}

# fail
{
   my $f = Future->new;

   $notifier->adopt_future( $f );

   $f->fail( "It failed", name => 1, 2, 3 );

   is( $err, "It failed", '$err after $f->fail' );
   is( $name, "name",     '$name after $f->fail' );
   is_deeply( \@detail, [ 1, 2, 3 ], '@detail after $f->fail' );

   is_refcount( $f, 1, '$f has refcount 1 after $f->fail' );

   undef $err;

   $f = Future->new;
   $notifier->adopt_future( $f->else_done() );

   $f->fail( "Not captured" );

   ok( !defined $err, '$err not defined after ->else_done suppressed failure' );
}

done_testing;