Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Basic unit test. Promises example.

  • Loading branch information...
commit 913cbc75d3f6a833ccffa27854a5c8d3b436ec57 1 parent 6c3536e
@agorman authored
Showing with 80 additions and 0 deletions.
  1. +36 −0 eg/eg-03-promises.pl
  2. +44 −0 t/01-basic.t
View
36 eg/eg-03-promises.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib qw(../lib);
+#use lib '/root/contrib/reflex/lib';
+
+# Job updates across the process boundary.
+
+{
+ package MyJob;
+ use Moose;
+ extends 'Reflex::Base';
+ with 'Reflex::Role::Collectible';
+ with 'Reflexive::WorkerPool::Role::Job';
+
+ # This method will be executed within it's own process
+ sub work {}
+}
+
+use Reflexive::WorkerPool;
+
+my $pool = Reflexive::WorkerPool->new;
+my @jobs = ( MyJob->new, MyJob->new, MyJob->new );
+
+$pool->enqueue_job(shift @jobs);
+
+while(my $event = $pool->next()) {
+ print "$event->{name}\n";
+
+ if ($event->{name} eq 'job_stopped') {
+ my $job = shift @jobs;
+ last unless $job;
+
+ $pool->enqueue_job($job);
+ }
+}
View
44 t/01-basic.t
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+use lib 'lib';
+use lib '/root/contrib/reflex/lib';
+
+{
+ package MyJob;
+ use Moose;
+ extends 'Reflex::Base';
+ with 'Reflex::Role::Collectible';
+ with 'Reflexive::WorkerPool::Role::Job';
+
+ sub work {}
+}
+
+use_ok 'Reflexive::WorkerPool';
+use_ok 'Reflexive::WorkerPool::Worker';
+
+my $worker_pool = Reflexive::WorkerPool->new();
+isa_ok $worker_pool, 'Reflexive::WorkerPool', 'WorkerPool Instantiated';
+
+my $job = MyJob->new();
+$worker_pool->enqueue_job($job);
+
+my ( $job_started, $job_stopped ) = ( 0, 0 );
+
+while (my $event = $worker_pool->next()) {
+ $job_started = 1 if $event->{name} eq 'job_started';
+ $job_stopped = 1 if $event->{name} eq 'job_stopped';
+
+ last if ($event->{name} eq 'job_stopped');
+}
+
+ok $job_started, 'got job_started event';
+ok $job_stopped, 'got_job stopped event';
+
+pass 'All done!';
+
+done_testing();
Please sign in to comment.
Something went wrong with that request. Please try again.