summaryrefslogtreecommitdiff
path: root/t/thread.t
blob: e94583219890c6afbe39df8eb7cb45ef8f19e5c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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' );