Release commit for 0.001001
[scpubgit/Object-Remote.git] / t / await.t
CommitLineData
eb9d5028 1use strictures 1;
2use Test::More;
3use Test::Fatal;
4use FindBin;
5use lib "$FindBin::Bin/lib";
6
7use Object::Remote;
8use Object::Remote::Future qw( await_all await_future );
9use ORTestClass;
10
11my $state = [];
12
13my $_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
21my $_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
28my @tests = (
29 ['proxy kept', $_make_future_keep_proxy],
30 ['proxy thrown away', $_make_future],
31);
32
33for 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
63done_testing;