line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Prove::Plugin::MySQLPool; |
2
|
1
|
|
|
1
|
|
88344
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
522
|
use File::Temp; |
|
1
|
|
|
|
|
22453
|
|
|
1
|
|
|
|
|
119
|
|
5
|
1
|
|
|
1
|
|
316
|
use POSIX::AtFork; |
|
1
|
|
|
|
|
537
|
|
|
1
|
|
|
|
|
56
|
|
6
|
1
|
|
|
1
|
|
344
|
use Test::mysqld::Pool; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
357
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub load { |
11
|
0
|
|
|
0
|
0
|
|
my ($class, $prove) = @_; |
12
|
0
|
|
|
|
|
|
my @args = @{ $prove->{args} }; |
|
0
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $preparer = $args[ 0 ]; |
14
|
0
|
|
0
|
|
|
|
my $jobs = $prove->{ app_prove }->jobs || 1; |
15
|
0
|
|
|
|
|
|
my $lib = $prove->{ app_prove }->lib; |
16
|
0
|
|
|
|
|
|
my $blib = $prove->{ app_prove }->blib; |
17
|
0
|
|
|
|
|
|
my $includes = $prove->{ app_prove }->includes; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $share_file = File::Temp->new(); # deleted when DESTROYed |
20
|
|
|
|
|
|
|
my $pool = Test::mysqld::Pool->new( |
21
|
|
|
|
|
|
|
jobs => $jobs, |
22
|
|
|
|
|
|
|
share_file => $share_file->filename, |
23
|
0
|
0
|
|
|
|
|
($preparer ? do { |
24
|
0
|
|
|
|
|
|
my @libs; |
25
|
0
|
0
|
|
|
|
|
push( @libs, 'lib' ) if $lib; |
26
|
0
|
0
|
|
|
|
|
push( @libs, 'blib/lib', 'blib/arch' ) if $blib; |
27
|
0
|
0
|
|
|
|
|
push( @libs, @$includes ) if @$includes; |
28
|
0
|
|
|
|
|
|
@libs = map { File::Spec->rel2abs($_) } @libs; |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
push( @INC, @libs ); |
30
|
0
|
0
|
|
|
|
|
eval "require $preparer" ## no critic |
31
|
|
|
|
|
|
|
or die "$@"; |
32
|
|
|
|
|
|
|
( |
33
|
|
|
|
|
|
|
preparer => sub { |
34
|
0
|
|
|
0
|
|
|
my ($mysqld) = @_; |
35
|
0
|
|
|
|
|
|
$preparer->prepare( $mysqld ); |
36
|
|
|
|
|
|
|
}, |
37
|
0
|
0
|
|
|
|
|
$preparer->can('my_cnf') ? ( my_cnf => $preparer->my_cnf ) : (), |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
} : ()), |
40
|
|
|
|
|
|
|
); |
41
|
0
|
|
|
|
|
|
$pool->prepare; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$prove->{ app_prove }{ __PACKAGE__ } = [ $pool, $share_file ]; # ref++ |
44
|
0
|
|
|
|
|
|
$prove->{ app_prove }->formatter('TAP::Formatter::MySQLPool'); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$ENV{ PERL_APP_PROVE_PLUGIN_MYSQLPOOL_SHARE_FILE } = $share_file->filename; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
POSIX::AtFork->add_to_child( \&child_hook ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub child_hook { |
54
|
0
|
|
|
0
|
0
|
|
my ($call) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# we're in the test process |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# prove uses 'fork' to create child processes |
59
|
|
|
|
|
|
|
# our own 'ps -o pid ...' uses 'backtick' |
60
|
|
|
|
|
|
|
# only hook 'fork' |
61
|
0
|
0
|
|
|
|
|
($call eq 'fork') |
62
|
|
|
|
|
|
|
or return; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $share_file = $ENV{ PERL_APP_PROVE_PLUGIN_MYSQLPOOL_SHARE_FILE } |
65
|
0
|
0
|
|
|
|
|
or return; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $dsn = Test::mysqld::Pool->new( share_file => $share_file )->alloc; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# use this in tests |
70
|
0
|
|
|
|
|
|
$ENV{ PERL_TEST_MYSQLPOOL_DSN } = $dsn; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
package TAP::Formatter::MySQLPool::Session; |
75
|
1
|
|
|
1
|
|
8
|
use parent 'TAP::Formatter::Console::Session'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub close_test { |
78
|
0
|
|
|
0
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $share_file = $ENV{ PERL_APP_PROVE_PLUGIN_MYSQLPOOL_SHARE_FILE } |
81
|
0
|
0
|
|
|
|
|
or return; |
82
|
0
|
|
|
|
|
|
Test::mysqld::Pool->new( share_file => $share_file )->dealloc_unused; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->SUPER::close_test(@_); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
package TAP::Formatter::MySQLPool; |
90
|
1
|
|
|
1
|
|
3809
|
use parent 'TAP::Formatter::Console'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub open_test { |
93
|
0
|
|
|
0
|
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
bless $self->SUPER::open_test(@_), 'TAP::Formatter::MySQLPool::Session'; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |