summaryrefslogtreecommitdiff
path: root/t/07notifier-future.t
diff options
context:
space:
mode:
Diffstat (limited to 't/07notifier-future.t')
-rw-r--r--t/07notifier-future.t58
1 files changed, 58 insertions, 0 deletions
diff --git a/t/07notifier-future.t b/t/07notifier-future.t
new file mode 100644
index 0000000..066fbb9
--- /dev/null
+++ b/t/07notifier-future.t
@@ -0,0 +1,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;