44
44
# Create the master thread
45
my $master = Padre::TaskThread->new->spawn;
46
isa_ok( $master, 'Padre::TaskThread' );
45
my $master = Padre::TaskWorker->new->spawn;
46
isa_ok( $master, 'Padre::TaskWorker' );
47
47
is( scalar( threads->list ), 1, 'Found 1 thread' );
48
ok( $master->is_running, 'Master is_running' );
48
ok( $master->thread->is_running, 'Master is_running' );
50
50
# Create a single worker
51
51
my $worker = Padre::TaskWorker->new;
52
52
isa_ok( $worker, 'Padre::TaskWorker' );
54
54
# Start the worker inside the master
55
ok( $master->start($worker), '->add ok' );
55
ok( $master->send_child($worker), '->add ok' );
56
56
TRACE("Pausing to allow worker thread startup...") if DEBUG;
57
57
sleep 0.15; #0.1 was not enough
58
58
is( scalar( threads->list ), 2, 'Found 2 threads' );
59
ok( $master->is_running, 'Master is_running' );
60
ok( !$master->is_joinable, 'Master is not is_joinable' );
61
ok( !$master->is_detached, 'Master is not is_detached' );
62
ok( $worker->is_running, 'Worker is_running' );
63
ok( !$worker->is_joinable, 'Worker is not is_joinable' );
64
ok( !$worker->is_detached, 'Worker is not is_detached' );
59
ok( $master->thread->is_running, 'Master is_running' );
60
ok( !$master->thread->is_joinable, 'Master is not is_joinable' );
61
ok( !$master->thread->is_detached, 'Master is not is_detached' );
62
ok( $worker->thread->is_running, 'Worker is_running' );
63
ok( !$worker->thread->is_joinable, 'Worker is not is_joinable' );
64
ok( !$worker->thread->is_detached, 'Worker is not is_detached' );
66
66
# Shut down the worker but leave the master running
67
ok( $worker->stop, '->stop ok' );
67
ok( $worker->send_stop, '->send_stop ok' );
68
68
TRACE("Pausing to allow worker thread shutdown...") if DEBUG;
70
ok( $master->is_running, 'Master is_running' );
71
ok( !$master->is_joinable, 'Master is not is_joinable' );
72
ok( !$master->is_detached, 'Master is not is_detached' );
73
ok( !$worker->thread, 'Worker thread has ended' );
70
ok( $master->thread->is_running, 'Master is_running' );
71
ok( !$master->thread->is_joinable, 'Master is not is_joinable' );
72
ok( !$master->thread->is_detached, 'Master is not is_detached' );
75
$worker->thread->join;
76
ok( !$worker->thread, 'Worker thread has ended' );
76
79
is( scalar( threads->list ), 1, 'Thread is gone' );