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: {
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" );
my @threads = threads->list;
is( scalar(@threads), 1, 'Found one thread' );
is( $threads[0]->tid, $tid, 'Found the expected thread id' );
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' );
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' );
$thread->stop;
sleep 1;
ok( !$thread->thread, '->thread no longer exists' );
}
is( scalar( threads->list ), 0, 'One thread exists' );