summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-07-11 21:53:12 +0100
committerdakkar <dakkar@thenautilus.net>2010-07-11 21:53:12 +0100
commit2ffb38324b6951790a08426ef74e422fecf041c1 (patch)
treed244288dec86e0808c8f784e21fa273d3452e583
parenttest for TT:Thread (diff)
downloadThread-Task-2ffb38324b6951790a08426ef74e422fecf041c1.tar.gz
Thread-Task-2ffb38324b6951790a08426ef74e422fecf041c1.tar.bz2
Thread-Task-2ffb38324b6951790a08426ef74e422fecf041c1.zip
test for TT::Worker
-rw-r--r--t/worker.t42
1 files changed, 42 insertions, 0 deletions
diff --git a/t/worker.t b/t/worker.t
new file mode 100644
index 0000000..33db0f4
--- /dev/null
+++ b/t/worker.t
@@ -0,0 +1,42 @@
+#!perl
+use strict;
+use warnings;
+use Test::Most tests => 17, 'die';
+use threads;
+use Thread::Task::Worker;
+use Thread::Task::Thread;
+
+is( scalar( threads->list ), 0, 'One thread exists' );
+SCOPE: {
+
+ # Create the master thread
+ my $master = Thread::Task::Thread->new->spawn;
+ isa_ok( $master, 'Thread::Task::Thread' );
+ is( scalar( threads->list ), 1, 'Found 1 thread' );
+ ok( $master->is_running, 'Master is_running' );
+
+ # Create a single worker
+ my $worker = Thread::Task::Worker->new;
+ isa_ok( $worker, 'Thread::Task::Worker' );
+
+ # Start the worker inside the master
+ $master->start($worker);
+ sleep 1;
+ is( scalar( threads->list ), 2, 'Found 2 threads' );
+ ok( $master->is_running, 'Master is_running' );
+ ok( !$master->is_joinable, 'Master is not is_joinable' );
+ ok( !$master->is_detached, 'Master is not is_detached' );
+ ok( $worker->is_running, 'Worker is_running' );
+ ok( !$worker->is_joinable, 'Worker is not is_joinable' );
+ ok( !$worker->is_detached, 'Worker is not is_detached' );
+
+ # Shut down the worker but leave the master running
+ $worker->stop;
+ sleep 1;
+ ok( $master->is_running, 'Master is_running' );
+ ok( !$master->is_joinable, 'Master is not is_joinable' );
+ ok( !$master->is_detached, 'Master is not is_detached' );
+ ok( !$worker->thread, 'Worker thread has ended' );
+}
+
+is( scalar( threads->list ), 1, 'Thread is gone' );