File: await.t

package info (click to toggle)
libobject-remote-perl 0.004000-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • ctags: 248
  • sloc: perl: 2,408; makefile: 7
file content (64 lines) | stat: -rw-r--r-- 1,451 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strictures 1;
use Test::More;
use Test::Fatal;
use FindBin;
use lib "$FindBin::Bin/lib";
$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;

use Object::Remote;
use Object::Remote::Future qw( await_all await_future );
use ORTestClass;

my $state = [];

my $_make_future_keep_proxy = sub {
  # note: do not store the remote proxy somewhere
  my $proxy = ORTestClass->new::on('-');
  my $future = $proxy->start::call_callback(23, sub { sleep 1 });
  push @$state, $proxy;
  return $future;
};

my $_make_future = sub {
  # note: do not store the remote proxy somewhere
  my $future = ORTestClass
    ->new::on('-')
    ->start::call_callback(23, sub { sleep 1 });
};

my @tests = (
  ['proxy kept', $_make_future_keep_proxy],
  ['proxy thrown away', $_make_future],
);

for my $test (@tests) {
  my ($title, $make) = @$test;
  subtest $title, sub {

    do {
      my $future = $make->();
      local $SIG{ALRM} = sub { die "future timed out" };
      alarm 10;
      is exception {
        my $result = await_future $future;
        is $result, 23, 'correct value';
        alarm 0;
      }, undef, 'no errors for await_future';
    };

    do {
      my $future = $make->();
      local $SIG{ALRM} = sub { die "future timed out" };
      alarm 10;
      is exception {
        my @result = await_all $future;
        is $result[0], 23, 'correct value';
        alarm 0;
      }, undef, 'no errors for await_all';
    };

    done_testing;
  };
}

done_testing;