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