Commit | Line | Data |
eb9d5028 |
1 | use strictures 1; |
2 | use Test::More; |
3 | use Test::Fatal; |
4 | use FindBin; |
5 | use lib "$FindBin::Bin/lib"; |
6 | |
7 | use Object::Remote; |
8 | use Object::Remote::Future qw( await_all await_future ); |
9 | use ORTestClass; |
10 | |
11 | my $state = []; |
12 | |
13 | my $_make_future_keep_proxy = sub { |
14 | # note: do not store the remote proxy somewhere |
15 | my $proxy = ORTestClass->new::on('-'); |
16 | my $future = $proxy->start::call_callback(23, sub { sleep 1 }); |
17 | push @$state, $proxy; |
18 | return $future; |
19 | }; |
20 | |
21 | my $_make_future = sub { |
22 | # note: do not store the remote proxy somewhere |
23 | my $future = ORTestClass |
24 | ->new::on('-') |
25 | ->start::call_callback(23, sub { sleep 1 }); |
26 | }; |
27 | |
28 | my @tests = ( |
29 | ['proxy kept', $_make_future_keep_proxy], |
30 | ['proxy thrown away', $_make_future], |
31 | ); |
32 | |
33 | for my $test (@tests) { |
34 | my ($title, $make) = @$test; |
35 | subtest $title, sub { |
36 | |
37 | do { |
38 | my $future = $make->(); |
39 | local $SIG{ALRM} = sub { die "future timed out" }; |
40 | alarm 10; |
41 | is exception { |
42 | my $result = await_future $future; |
43 | is $result, 23, 'correct value'; |
44 | alarm 0; |
45 | }, undef, 'no errors for await_future'; |
46 | }; |
47 | |
48 | do { |
49 | my $future = $make->(); |
50 | local $SIG{ALRM} = sub { die "future timed out" }; |
51 | alarm 10; |
52 | is exception { |
53 | my @result = await_all $future; |
54 | is $result[0], 23, 'correct value'; |
55 | alarm 0; |
56 | }, undef, 'no errors for await_all'; |
57 | }; |
58 | |
59 | done_testing; |
60 | }; |
61 | } |
62 | |
63 | done_testing; |