summaryrefslogtreecommitdiff
path: root/t/signal.t
diff options
context:
space:
mode:
Diffstat (limited to 't/signal.t')
-rw-r--r--t/signal.t49
1 files changed, 49 insertions, 0 deletions
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' );