From 0581dbd91216c18ded2812ec9f3527c0a889da76 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 12 Jul 2010 21:50:31 +0100 Subject: test for TT::Manager & signaling --- t/signal.t | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 t/signal.t (limited to 't/signal.t') 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' ); -- cgit v1.2.3