::Logging::TestLogger package decleration had wrong name
[scpubgit/Object-Remote.git] / t / start_core.t
CommitLineData
11e7c8a5 1use strictures 1;
2use Test::More;
a7111726 3use Object::Remote;
4use File::Spec;
11e7c8a5 5
abef6e5b 6$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
f129bfaf 7
11e7c8a5 8{
9 package S1S;
10
11 use Moo;
12
13 sub get_s2 {
14 S2S->new
15 }
16}
17
18{
19 package S1F;
20
21 use Object::Remote::Future;
22 use Moo;
23
24 our $C;
25
26 sub get_s2 {
9822fc76 27 shift->maybe::start::_real_get_s2;
28 }
29
30 sub _real_get_s2 {
11e7c8a5 31 future {
32 my $f = shift;
a7111726 33 $C = sub { $f->done(S2F->new); undef($f); undef($C); };
11e7c8a5 34 $f;
35 }
36 }
37}
38
39{
40 package S2S;
41
42 use Moo;
43
44 sub get_s3 { 'S3' }
45}
46
47{
48 package S2F;
49
50 use Object::Remote::Future;
51 use Moo;
52
53 our $C;
54
55 sub get_s3 {
56 future {
57 my $f = shift;
a7111726 58 $C = sub { $f->done('S3'); undef($f); undef($C); };
11e7c8a5 59 $f;
60 }
61 }
62}
63
64my $res;
65
66S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
67
68is($res, 'S3', 'Synchronous code ok');
69
70undef($res);
71
72S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
73
74ok(!$S2F::C, 'Second future not yet constructed');
75
76$S1F::C->();
77
78ok($S2F::C, 'Second future constructed after first future completed');
79
80ok(!$res, 'Nothing happened yet');
81
82$S2F::C->();
83
84is($res, 'S3', 'Asynchronous code ok');
85
a7111726 86is(S1S->get_s2->get_s3, 'S3', 'Sync without start');
87
befabdee 88Object::Remote->current_loop->watch_time(
89 after => 0.1,
90 code => sub {
91 $S1F::C->();
92 Object::Remote->current_loop->watch_time(
93 after => 0.1,
94 code => sub { $S2F::C->() }
95 );
a7111726 96 }
97);
98
99is(S1F->get_s2->get_s3, 'S3', 'Async without start');
100
11e7c8a5 101done_testing;