force-load Moo::HandleMoose::_TypeMap
[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";
abef6e5b 6$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
eb9d5028 7
8use Object::Remote;
9use Object::Remote::Future qw( await_all await_future );
10use ORTestClass;
11
12my $state = [];
13
14my $_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
22my $_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
29my @tests = (
30 ['proxy kept', $_make_future_keep_proxy],
31 ['proxy thrown away', $_make_future],
32);
33
34for 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
64done_testing;