line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Class::Moose::Executor::Parallel; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Execute tests in parallel (parallelized by instance) |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
187
|
use 5.010000; |
|
11
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.98'; |
8
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
55
|
use Moose 2.0000; |
|
11
|
|
|
|
|
154
|
|
|
11
|
|
|
|
|
88
|
|
10
|
11
|
|
|
11
|
|
69069
|
use Carp; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
539
|
|
11
|
11
|
|
|
11
|
|
198
|
use namespace::autoclean; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
88
|
|
12
|
|
|
|
|
|
|
with 'Test::Class::Moose::Role::Executor'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Needs to come before we load other test tools |
15
|
11
|
|
|
11
|
|
5643
|
use Test2::IPC; |
|
11
|
|
|
|
|
9053
|
|
|
11
|
|
|
|
|
66
|
|
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
11
|
|
60874
|
use List::SomeUtils qw( none part ); |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
517
|
|
18
|
11
|
|
|
11
|
|
55
|
use Parallel::ForkManager; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
275
|
|
19
|
11
|
|
|
11
|
|
55
|
use Scalar::Util qw(reftype); |
|
11
|
|
|
|
|
462
|
|
|
11
|
|
|
|
|
517
|
|
20
|
11
|
|
|
11
|
|
5225
|
use TAP::Formatter::Color 3.29; |
|
11
|
|
|
|
|
98450
|
|
|
11
|
|
|
|
|
308
|
|
21
|
11
|
|
|
11
|
|
55
|
use Test2::API qw( test2_stack ); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
451
|
|
22
|
11
|
|
|
11
|
|
4873
|
use Test2::AsyncSubtest 0.000018 (); |
|
11
|
|
|
|
|
93830
|
|
|
11
|
|
|
|
|
253
|
|
23
|
11
|
|
|
11
|
|
66
|
use Test::Class::Moose::AttributeRegistry; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
253
|
|
24
|
11
|
|
|
11
|
|
4939
|
use Test::Class::Moose::Report::Class; |
|
11
|
|
|
|
|
55
|
|
|
11
|
|
|
|
|
407
|
|
25
|
11
|
|
|
11
|
|
99
|
use Try::Tiny; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
8525
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'jobs' => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => 'Int', |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has color_output => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => 'Bool', |
36
|
|
|
|
|
|
|
default => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has show_parallel_progress => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => 'Bool', |
42
|
|
|
|
|
|
|
default => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has '_fork_manager' => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => 'Parallel::ForkManager', |
48
|
|
|
|
|
|
|
init_arg => undef, |
49
|
|
|
|
|
|
|
lazy => 1, |
50
|
|
|
|
|
|
|
builder => '_build_fork_manager', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has '_subtests' => ( |
54
|
|
|
|
|
|
|
traits => ['Hash'], |
55
|
|
|
|
|
|
|
is => 'bare', |
56
|
|
|
|
|
|
|
isa => 'HashRef[Test2::AsyncSubtest]', |
57
|
|
|
|
|
|
|
init_arg => sub { {} }, |
58
|
|
|
|
|
|
|
handles => { |
59
|
|
|
|
|
|
|
_save_subtest => 'set', |
60
|
|
|
|
|
|
|
_saved_subtest => 'get', |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has '_color' => ( |
65
|
|
|
|
|
|
|
is => 'ro', |
66
|
|
|
|
|
|
|
isa => 'TAP::Formatter::Color', |
67
|
|
|
|
|
|
|
lazy => 1, |
68
|
|
|
|
|
|
|
builder => '_build_color', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
around _run_test_classes => sub { |
72
|
|
|
|
|
|
|
my $orig = shift; |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
my @test_classes = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my ( $seq, $par ) |
77
|
|
|
|
|
|
|
= part { $self->_test_class_is_parallelizable($_) } @test_classes; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->_run_test_classes_in_parallel($par); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->$orig( @{$seq} ) |
82
|
|
|
|
|
|
|
if $seq && @{$seq}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _test_class_is_parallelizable { |
88
|
121
|
|
|
121
|
|
231
|
my ( $self, $test_class ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return none { |
91
|
297
|
|
|
297
|
|
638
|
Test::Class::Moose::AttributeRegistry->method_has_tag( |
92
|
|
|
|
|
|
|
$test_class, |
93
|
|
|
|
|
|
|
$_, |
94
|
|
|
|
|
|
|
'noparallel' |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
121
|
|
|
|
|
561
|
$self->_test_methods_for($test_class); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _run_test_classes_in_parallel { |
101
|
11
|
|
|
11
|
|
22
|
my $self = shift; |
102
|
11
|
|
|
|
|
22
|
my $test_classes = shift; |
103
|
|
|
|
|
|
|
|
104
|
11
|
|
|
|
|
22
|
for my $test_class ( @{$test_classes} ) { |
|
11
|
|
|
|
|
44
|
|
105
|
65
|
|
|
|
|
3245
|
my $subtest = Test2::AsyncSubtest->new( |
106
|
|
|
|
|
|
|
name => $test_class, |
107
|
|
|
|
|
|
|
hub_init_args => { manual_skip_all => 1 }, |
108
|
|
|
|
|
|
|
); |
109
|
65
|
|
|
|
|
80871
|
my $id = $subtest->cleave; |
110
|
65
|
100
|
|
|
|
5712
|
if ( my $pid = $self->_fork_manager->start ) { |
111
|
55
|
|
|
|
|
402657
|
$self->_save_subtest( $pid => $subtest ); |
112
|
55
|
|
|
|
|
983
|
next; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# This chunk of code only runs in child processes |
116
|
10
|
|
|
|
|
126363
|
my $class_report; |
117
|
10
|
|
|
|
|
530
|
$subtest->attach($id); |
118
|
|
|
|
|
|
|
$subtest->run( |
119
|
|
|
|
|
|
|
sub { |
120
|
10
|
|
|
10
|
|
20162
|
$class_report = $self->run_test_class($test_class); |
121
|
|
|
|
|
|
|
} |
122
|
10
|
|
|
|
|
27735
|
); |
123
|
10
|
|
|
|
|
2487
|
$subtest->detach; |
124
|
10
|
|
|
|
|
14508
|
$self->_fork_manager->finish( 0, \$class_report ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
341
|
$self->_fork_manager->wait_all_children; |
128
|
1
|
|
|
|
|
8113
|
test2_stack()->top->cull; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
162
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _build_fork_manager { |
134
|
11
|
|
|
11
|
|
22
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
11
|
|
|
|
|
319
|
my $pfm = Parallel::ForkManager->new( $self->jobs ); |
137
|
|
|
|
|
|
|
$pfm->run_on_finish( |
138
|
|
|
|
|
|
|
sub { |
139
|
48
|
|
|
48
|
|
83340047
|
my ( $pid, $class_report ) = @_[ 0, 5 ]; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
try { |
142
|
48
|
|
|
|
|
8965
|
$self->test_report->add_test_class( ${$class_report} ); |
|
48
|
|
|
|
|
2381
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
catch { |
145
|
0
|
|
|
|
|
0
|
warn $_; |
146
|
48
|
|
|
|
|
1864
|
}; |
147
|
|
|
|
|
|
|
|
148
|
48
|
|
|
|
|
3060
|
my $subtest = $self->_saved_subtest($pid); |
149
|
48
|
50
|
|
|
|
283
|
unless ($subtest) { |
150
|
0
|
|
|
|
|
0
|
warn |
151
|
|
|
|
|
|
|
"Child process $pid ended but there is no active subtest for that pid!"; |
152
|
0
|
|
|
|
|
0
|
return; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
48
|
|
|
|
|
512
|
$subtest->finish; |
156
|
|
|
|
|
|
|
} |
157
|
11
|
|
|
|
|
43219
|
); |
158
|
|
|
|
|
|
|
|
159
|
11
|
|
|
|
|
418
|
return $pfm; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
around run_test_method => sub { |
163
|
|
|
|
|
|
|
my $orig = shift; |
164
|
|
|
|
|
|
|
my $self = shift; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $method_report = $self->$orig(@_); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
return $method_report unless $self->show_parallel_progress; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# we're running under parallel testing, so rather than having |
171
|
|
|
|
|
|
|
# the code look like it's stalled, we'll output a dot for |
172
|
|
|
|
|
|
|
# every test method. |
173
|
|
|
|
|
|
|
my ( $color, $text ) |
174
|
|
|
|
|
|
|
= $method_report->passed |
175
|
|
|
|
|
|
|
? ( 'green', '.' ) |
176
|
|
|
|
|
|
|
: ( 'red', 'X' ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# The set_color() method from TAP::Formatter::Color is just ugly. |
179
|
|
|
|
|
|
|
if ( $self->color_output ) { |
180
|
|
|
|
|
|
|
$self->_color->set_color( |
181
|
|
|
|
|
|
|
sub { print STDERR shift, $text }, |
182
|
|
|
|
|
|
|
$color, |
183
|
|
|
|
|
|
|
); |
184
|
|
|
|
|
|
|
$self->_color->set_color( sub { print STDERR shift }, 'reset' ); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
|
|
|
|
|
|
print STDERR $text; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
return $method_report; |
191
|
|
|
|
|
|
|
}; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _build_color { |
194
|
9
|
|
|
9
|
|
506
|
return TAP::Formatter::Color->new; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=pod |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=encoding UTF-8 |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 NAME |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Test::Class::Moose::Executor::Parallel - Execute tests in parallel (parallelized by instance) |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 VERSION |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
version 0.98 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=for Pod::Coverage Tags Tests runtests |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SUPPORT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/test-class-moose/issues>. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 SOURCE |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
The source code repository for Test-Class-Moose can be found at L<https://github.com/houseabsolute/test-class-moose>. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 AUTHORS |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over 4 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Curtis "Ovid" Poe <ovid@cpan.org> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This software is copyright (c) 2012 - 2019 by Curtis "Ovid" Poe. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
244
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
The full text of the license can be found in the |
247
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |