summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/lib/Test/Conduit.pm30
-rw-r--r--t/signal.t49
2 files changed, 79 insertions, 0 deletions
diff --git a/t/lib/Test/Conduit.pm b/t/lib/Test/Conduit.pm
new file mode 100644
index 0000000..02454e7
--- /dev/null
+++ b/t/lib/Test/Conduit.pm
@@ -0,0 +1,30 @@
+use 5.008003;
+use MooseX::Declare;
+
+class Test::Conduit with Thread::Task::Role::Conduit {
+ use Thread::Queue;
+ use Thread::Task::Types qw(Queue_T);
+
+ has queue => (
+ isa => Queue_T,
+ is => 'ro',
+ init_arg => undef,
+ default => sub { Thread::Queue->new },
+ handles => {
+ signal => 'enqueue',
+ pop => 'dequeue',
+ },
+ );
+
+ method runloop() {
+ while (my $msg=$self->pop) {
+ $self->manager->on_signal($msg);
+ }
+ }
+
+ method runonce() {
+ $self->manager->on_signal($self->pop);
+ }
+}
+
+1;
diff --git a/t/signal.t b/t/signal.t
new file mode 100644
index 0000000..81e984e
--- /dev/null
+++ b/t/signal.t
@@ -0,0 +1,49 @@
+#!perl
+use strict;
+use warnings;
+use Test::Most tests => 10, 'die';
+use threads;
+use lib 't/lib';
+use Thread::Task::Manager;
+use Test::Addition;
+use Test::Conduit;
+
+is( scalar( threads->list ), 0, 'No threads' );
+SCOPE: {
+ my $conduit = Test::Conduit->new();
+
+ my $manager = Thread::Task::Manager->new( conduit => $conduit );
+ isa_ok( $manager, 'Thread::Task::Manager' );
+ is( scalar( threads->list ), 0, 'No threads' );
+
+ # Run the startup process
+ $manager->start;
+ sleep(1);
+ is( scalar( threads->list ), $manager->minimum+1, 'Three threads exists' );
+
+ # Create the sample task
+ my $addition = Test::Addition->new(
+ x => 2,
+ y => 3,
+ );
+ isa_ok( $addition, 'Test::Addition' );
+
+ # Schedule the task (which should trigger its execution)
+ $manager->schedule($addition);
+
+ # Only the prepare phase should run (for now)
+ is( $addition->prepare_cnt, 1, '->prepare_cnt is 1' );
+ is( $addition->run_cnt, 0, '->run_cnt is 0' );
+ is( $addition->finish_cnt, 0, '->finish_cnt is 0' );
+
+ $conduit->runonce();
+ $conduit->runonce();
+
+ # Run the shutdown process
+ $manager->stop;
+ sleep(1);
+ is( scalar( threads->list ), 0, 'No threads' );
+}
+
+# Do we start with no threads as expected
+is( scalar( threads->list ), 0, 'No threads' );