summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-07-11 21:28:59 +0100
committerdakkar <dakkar@thenautilus.net>2010-07-11 21:28:59 +0100
commit852eff7457517966f98f9a936ac7d5762da7aa0c (patch)
tree2dd840bc20cde12e82256a44eb020386c1f859f1
parentnow it compiles (diff)
downloadThread-Task-852eff7457517966f98f9a936ac7d5762da7aa0c.tar.gz
Thread-Task-852eff7457517966f98f9a936ac7d5762da7aa0c.tar.bz2
Thread-Task-852eff7457517966f98f9a936ac7d5762da7aa0c.zip
test for TT:Thread
-rw-r--r--lib/Thread/Task/Thread.pm8
-rw-r--r--t/thread.t43
2 files changed, 50 insertions, 1 deletions
diff --git a/lib/Thread/Task/Thread.pm b/lib/Thread/Task/Thread.pm
index d3fa27a..e922549 100644
--- a/lib/Thread/Task/Thread.pm
+++ b/lib/Thread/Task/Thread.pm
@@ -62,6 +62,12 @@ class Thread::Task::Thread {
threads->object( $self->tid );
}
+ # always refresh the 'thread' attribute
+ # we use it only as a delegation point
+ after thread() {
+ $self->_clear_thread;
+ }
+
method spawn() {
$self->_clear_thread;
$WID2TID{$self->wid} =
@@ -108,7 +114,7 @@ class Thread::Task::Thread {
next unless $self->can($method);
try {
- $self->$method(@$method);
+ $self->$method(@$message);
}
catch (Finished_ET $e) {
last;
diff --git a/t/thread.t b/t/thread.t
new file mode 100644
index 0000000..e945832
--- /dev/null
+++ b/t/thread.t
@@ -0,0 +1,43 @@
+#!perl
+use strict;
+use warnings;
+use Test::Most tests => 17, 'die';
+use threads;
+use Thread::Task::Thread;
+
+is( scalar( threads->list ), 0, 'One thread exists' );
+
+SCOPE: {
+ # Create the master thread
+ my $thread = Thread::Task::Thread->new->spawn;
+ isa_ok( $thread, 'Thread::Task::Thread' );
+ is( $thread->wid, 1, '->wid ok' );
+ isa_ok( $thread->queue, 'Thread::Queue' );
+ isa_ok( $thread->thread, 'threads' );
+ ok( !$thread->is_thread, '->is_thread is false' );
+ my $tid = $thread->thread->tid;
+ ok( $tid, "Got thread id $tid" );
+
+ # Does the threads module agree it was created
+ my @threads = threads->list;
+ is( scalar(@threads), 1, 'Found one thread' );
+ is( $threads[0]->tid, $tid, 'Found the expected thread id' );
+
+ # Initially, the thread should be running
+ ok( $thread->is_running, 'Thread is_running' );
+ ok( !$thread->is_joinable, 'Thread is not is_joinable' );
+ ok( !$thread->is_detached, 'Thread is not is_detached' );
+
+ # It should stay running
+ sleep 0.1;
+ ok( $thread->is_running, 'Thread is_running' );
+ ok( !$thread->is_joinable, 'Thread is not is_joinable' );
+ ok( !$thread->is_detached, 'Thread is not is_detached' );
+
+ # Instruct the master to shutdown, and give it a brief time to do so.
+ $thread->stop;
+ sleep 1;
+ ok( !$thread->thread, '->thread no longer exists' );
+}
+
+is( scalar( threads->list ), 0, 'One thread exists' );