force-load Moo::HandleMoose::_TypeMap
[scpubgit/Object-Remote.git] / t / start_core.t
index 31d5349..cb2ed87 100644 (file)
@@ -1,5 +1,9 @@
 use strictures 1;
 use Test::More;
+use Object::Remote;
+use File::Spec;
+
+$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
 
 {
   package S1S;
@@ -20,9 +24,13 @@ use Test::More;
   our $C;
 
   sub get_s2 {
+    shift->maybe::start::_real_get_s2;
+  }
+
+  sub _real_get_s2 {
     future {
       my $f = shift;
-      $C = sub { $f->done(S2F->new); undef($f); };
+      $C = sub { $f->done(S2F->new); undef($f); undef($C); };
       $f;
     }
   }
@@ -47,7 +55,7 @@ use Test::More;
   sub get_s3 {
     future {
       my $f = shift;
-      $C = sub { $f->done('S3'); undef($f); };
+      $C = sub { $f->done('S3'); undef($f); undef($C); };
       $f;
     }
   }
@@ -55,13 +63,17 @@ use Test::More;
 
 my $res;
 
-S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
+my @keep;
+
+push @keep,
+  S1S->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
 
 is($res, 'S3', 'Synchronous code ok');
 
 undef($res);
 
-S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
+push @keep,
+  S1F->start::get_s2->then::get_s3->on_ready(sub { ($res) = $_[0]->get });
 
 ok(!$S2F::C, 'Second future not yet constructed');
 
@@ -75,4 +87,19 @@ $S2F::C->();
 
 is($res, 'S3', 'Asynchronous code ok');
 
+is(S1S->get_s2->get_s3, 'S3', 'Sync without start');
+
+Object::Remote->current_loop->watch_time(
+  after => 0.1,
+  code => sub {
+    $S1F::C->();
+    Object::Remote->current_loop->watch_time(
+      after => 0.1,
+      code => sub { $S2F::C->() }
+    );
+  }
+);
+
+is(S1F->get_s2->get_s3, 'S3', 'Async without start');
+
 done_testing;