Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / 52leaks.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
66917da3 3# work around brain damage in PPerl (yes, it has to be a global)
4$SIG{__WARN__} = sub {
5 warn @_ unless $_[0] =~ /\QUse of "goto" to jump into a construct is deprecated/
6} if ($ENV{DBICTEST_IN_PERSISTENT_ENV});
7
8# the persistent environments run with this flag first to see if
9# we will run at all (e.g. it will fail if $^X doesn't match)
10exit 0 if $ENV{DBICTEST_PERSISTENT_ENV_BAIL_EARLY};
11
f05edfd1 12# Do the override as early as possible so that CORE::bless doesn't get compiled away
13# We will replace $bless_override only if we are in author mode
14my $bless_override;
15BEGIN {
16 $bless_override = sub {
17 CORE::bless( $_[0], (@_ > 1) ? $_[1] : caller() );
18 };
19 *CORE::GLOBAL::bless = sub { goto $bless_override };
20}
21
50261284 22use strict;
23use warnings;
a917fb06 24use Test::More;
d5e5fb4b 25
c0329273 26
30c81ba9 27use DBICTest::RunMode;
ee20935b 28use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry visit_refs);
29use Scalar::Util qw(weaken blessed reftype);
30use DBIx::Class::_Util qw(hrefaddr sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt);
31BEGIN {
32 plan skip_all => "Your perl version $] appears to leak like a sieve - skipping test"
33 if DBIx::Class::_ENV_::PEEPEENESS;
34}
30c81ba9 35
30c81ba9 36
66917da3 37my $TB = Test::More->builder;
38if ($ENV{DBICTEST_IN_PERSISTENT_ENV}) {
ee20935b 39 # without this explicit close TB warns in END after a ->reset
40 close ($TB->$_) for qw(output failure_output todo_output);
66917da3 41
ee20935b 42 # newer TB does not auto-reopen handles
43 if ( modver_gt_or_eq( 'Test::More', '1.200' ) ) {
44 open ($TB->$_, '>&', *STDERR)
45 for qw( failure_output todo_output );
7be5717e 46 open ($TB->output, '>&', *STDOUT);
47 }
48
49 # so done_testing can work on every persistent pass
50 $TB->reset;
66917da3 51}
52
a8c2c746 53# this is what holds all weakened refs to be checked for leakage
54my $weak_registry = {};
55
6a43bc0c 56# whether or to invoke IC::DT
57my $has_dt;
58
a8c2c746 59# Skip the heavy-duty leak tracing when just doing an install
8b60b921 60# or when having Moose crap all over everything
61if ( !$ENV{DBICTEST_VIA_REPLICATED} and !DBICTest::RunMode->is_plain ) {
f05edfd1 62
eb7aa960 63 # redefine the bless override so that we can catch each and every object created
a8c2c746 64 no warnings qw/redefine once/;
65 no strict qw/refs/;
66
f05edfd1 67 $bless_override = sub {
68
a8c2c746 69 my $obj = CORE::bless(
70 $_[0], (@_ > 1) ? $_[1] : do {
71 my ($class, $fn, $line) = caller();
72 fail ("bless() of $_[0] into $class without explicit class specification at $fn line $line")
73 if $class =~ /^ (?: DBIx\:\:Class | DBICTest ) /x;
74 $class;
75 }
76 );
77
8d6b1478 78 # unicode is tricky, and now we happen to invoke it early via a
79 # regex in connection()
80 return $obj if (ref $obj) =~ /^utf8/;
81
7be5717e 82 # Test Builder is now making a new object for every pass/fail (que bloat?)
83 # and as such we can't really store any of its objects (since it will
84 # re-populate the registry while checking it, ewwww!)
ee20935b 85 return $obj if (ref $obj) =~ /^TB2::|^Test::Stream/;
7be5717e 86
5dc4301c 87 # populate immediately to avoid weird side effects
65d35121 88 return populate_weakregistry ($weak_registry, $obj );
a8c2c746 89 };
90
eb7aa960 91 require Try::Tiny;
a8c2c746 92 for my $func (qw/try catch finally/) {
93 my $orig = \&{"Try::Tiny::$func"};
94 *{"Try::Tiny::$func"} = sub (&;@) {
65d35121 95 populate_weakregistry( $weak_registry, $_[0] );
a8c2c746 96 goto $orig;
97 }
98 }
eb7aa960 99
100 # Some modules are known to install singletons on-load
101 # Load them and empty the registry
102
103 # this loads the DT armada
54a9a088 104 $has_dt = DBIx::Class::Optional::Dependencies->req_ok_for([qw( test_rdbms_sqlite ic_dt )]);
eb7aa960 105
106 require Errno;
107 require DBI;
108 require DBD::SQLite;
109 require FileHandle;
e6ff3658 110 require Moo;
eb7aa960 111
112 %$weak_registry = ();
a8c2c746 113}
114
115{
66917da3 116 use_ok ('DBICTest');
a917fb06 117
a8c2c746 118 my $schema = DBICTest->init_schema;
119 my $rs = $schema->resultset ('Artist');
120 my $storage = $schema->storage;
a917fb06 121
052b8ce2 122 my $row_obj = $rs->search({}, { rows => 1})->next; # so that commits/rollbacks work
a8c2c746 123 ok ($row_obj, 'row from db');
124
052b8ce2 125 # txn_do to invoke more codepaths
a8c2c746 126 my ($mc_row_obj, $pager, $pager_explicit_count) = $schema->txn_do (sub {
127
9345b14c 128 my $artist = $schema->resultset('Artist')->create ({
a8c2c746 129 name => 'foo artist',
130 cds => [{
131 title => 'foo cd',
132 year => 1984,
187ec69a 133 tracks => [
134 { title => 't1' },
135 { title => 't2' },
136 ],
137 genre => { name => 'mauve' },
a8c2c746 138 }],
139 });
140
141 my $pg = $rs->search({}, { rows => 1})->page(2)->pager;
142
143 my $pg_wcount = $rs->page(4)->pager->total_entries (66);
144
145 return ($artist, $pg, $pg_wcount);
146 });
147
9345b14c 148 # more codepaths - error handling in txn_do
149 {
150 eval { $schema->txn_do ( sub {
151 $storage->_dbh->begin_work;
152 fail ('how did we get so far?!');
153 } ) };
154
155 eval { $schema->txn_do ( sub {
156 $schema->txn_do ( sub {
157 die "It's called EXCEPTION";
158 fail ('how did we get so far?!');
159 } );
160 fail ('how did we get so far?!');
161 } ) };
162 like( $@, qr/It\'s called EXCEPTION/, 'Exception correctly propagated in nested txn_do' );
163 }
164
165 # dbh_do codepath
187ec69a 166 my ($rs_bind_circref, $cond_rowobj) = $schema->storage->dbh_do ( sub {
167 my $row = $_[0]->schema->resultset('Artist')->new({});
168 my $rs = $_[0]->schema->resultset('Artist')->search({
169 name => $row, # this is deliberately bogus, see FIXME below!
170 });
171 return ($rs, $row);
172 });
173
a8c2c746 174 is ($pager->next_page, 3, 'There is one more page available');
175
176 # based on 66 per 10 pages
177 is ($pager_explicit_count->last_page, 7, 'Correct last page');
551e711a 178
052b8ce2 179 # do some population (invokes some extra codepaths)
180 # also exercise the guard code and the manual txn control
181 {
182 my $guard = $schema->txn_scope_guard;
183 # populate with bindvars
184 $rs->populate([{ name => 'James Bound' }]);
185 $guard->commit;
186
187 $schema->txn_begin;
188 # populate mixed
189 $rs->populate([{ name => 'James Rebound', rank => \ '11' }]);
190 $schema->txn_commit;
191
192 $schema->txn_begin;
193 # and without bindvars
194 $rs->populate([{ name => \ '"James Unbound"' }]);
195 $schema->txn_rollback;
196 }
197
0a03206a 198 # prefetching
199 my $cds_rs = $schema->resultset('CD');
200 my $cds_with_artist = $cds_rs->search({}, { prefetch => 'artist' });
201 my $cds_with_tracks = $cds_rs->search({}, { prefetch => 'tracks' });
202 my $cds_with_stuff = $cds_rs->search({}, { prefetch => [ 'genre', { artist => { cds => { tracks => 'cd_single' } } } ] });
203
204 # implicit pref
205 my $cds_with_impl_artist = $cds_rs->search({}, { columns => [qw/me.title artist.name/], join => 'artist' });
206
207 # get_column
208 my $getcol_rs = $cds_rs->get_column('me.cdid');
209 my $pref_getcol_rs = $cds_with_stuff->get_column('me.cdid');
210
a8c2c746 211 my $base_collection = {
a8c2c746 212 resultset => $rs,
307ab4c5 213
0a03206a 214 pref_precursor => $cds_rs,
215
216 pref_rs_single => $cds_with_artist,
217 pref_rs_multi => $cds_with_tracks,
218 pref_rs_nested => $cds_with_stuff,
219
220 pref_rs_implicit => $cds_with_impl_artist,
221
222 pref_row_single => $cds_with_artist->next,
223 pref_row_multi => $cds_with_tracks->next,
224 pref_row_nested => $cds_with_stuff->next,
225
226 # even though this does not leak Storable croaks on it :(((
227 #pref_row_implicit => $cds_with_impl_artist->next,
228
229 get_column_rs_plain => $getcol_rs,
230 get_column_rs_pref => $pref_getcol_rs,
231
37aafa2e 232 # twice so that we make sure only one H::M object spawned
b35500f1 233 chained_resultset => $rs->search_rs ({}, { '+columns' => { foo => 'artistid' } } ),
234 chained_resultset2 => $rs->search_rs ({}, { '+columns' => { bar => 'artistid' } } ),
37aafa2e 235
a8c2c746 236 row_object => $row_obj,
551e711a 237
187ec69a 238 mc_row_object => $mc_row_obj,
239
a8c2c746 240 result_source => $rs->result_source,
551e711a 241
4376a157 242 result_source_handle => $rs->result_source->handle,
243
a8c2c746 244 pager_explicit_count => $pager_explicit_count,
187ec69a 245
246 leaky_resultset => $rs_bind_circref,
247 leaky_resultset_cond => $cond_rowobj,
a8c2c746 248 };
574d9b69 249
6ae62c5c 250 # fire all resultsets multiple times, once here, more below
251 # some of these can't find anything (notably leaky_resultset)
252 my @rsets = grep {
253 blessed $_
254 and
255 (
256 $_->isa('DBIx::Class::ResultSet')
257 or
258 $_->isa('DBIx::Class::ResultSetColumn')
259 )
260 } values %$base_collection;
261
262
263 my $fire_resultsets = sub {
264 local $ENV{DBIC_COLUMNS_INCLUDE_FILTER_RELS} = 1;
265 local $SIG{__WARN__} = sigwarn_silencer(
266 qr/Unable to deflate 'filter'-type relationship 'artist'.+related object primary key not retrieved/
267 );
268
269 map
270 { $_, (blessed($_) ? { $_->get_columns } : ()) }
271 map
272 { $_->all }
273 @rsets
274 ;
275 };
b35500f1 276
6ae62c5c 277 push @{$base_collection->{random_results}}, $fire_resultsets->();
b35500f1 278
279 # FIXME - something throws a Storable for a spin if we keep
280 # the results in-collection. The same problem is seen above,
281 # swept under the rug back in 0a03206a, damned lazy ribantainer
282{
283 local $base_collection->{random_results};
218b7c12 284
eb7aa960 285 require Storable;
4376a157 286 %$base_collection = (
287 %$base_collection,
288 refrozen => Storable::dclone( $base_collection ),
289 rerefrozen => Storable::dclone( Storable::dclone( $base_collection ) ),
0a03206a 290 pref_row_implicit => $cds_with_impl_artist->next,
4376a157 291 schema => $schema,
292 storage => $storage,
293 sql_maker => $storage->sql_maker,
294 dbh => $storage->_dbh,
cd122820 295 fresh_pager => $rs->page(5)->pager,
296 pager => $pager,
4376a157 297 );
b35500f1 298}
4376a157 299
21aa86aa 300 # FIXME - ideally this kind of collector ought to be global, but attempts
301 # with an invasive debugger-based tracer did not quite work out... yet
302 # Manually scan the innards of everything we have in the base collection
303 # we assembled so far (skip the DT madness below) *recursively*
304 #
305 # Only do this when we do have the bits to look inside CVs properly,
306 # without it we are liable to pick up object defaults that are locked
307 # in method closures
308 if (DBICTest::Util::LeakTracer::CV_TRACING) {
309 visit_refs(
310 refs => [ $base_collection ],
311 action => sub {
312 populate_weakregistry ($weak_registry, $_[0]);
313 1; # true means "keep descending"
314 },
315 );
6ae62c5c 316
317 # do a heavy-duty fire-and-compare loop on all resultsets
318 # this is expensive - not running on install
319 my $typecounts = {};
014846ee 320 if (
321 ! DBICTest::RunMode->is_plain
322 and
323 ! $ENV{DBICTEST_IN_PERSISTENT_ENV}
014846ee 324 ) {
6ae62c5c 325
326 # FIXME - ideally we should be able to just populate an alternative
327 # registry, subtract everything from the main one, and arrive at
328 # an "empty" resulting hash
329 # However due to gross inefficiencies in the ::ResultSet code we
330 # end up recalculating a new set of aliasmaps which could have very
331 # well been cached if it wasn't for... anyhow
332 # What we do here for the time being is similar to the lazy approach
333 # of Devel::LeakTrace - we just make sure we do not end up with more
334 # reftypes than when we started. At least we are not blanket-counting
335 # SVs like D::LT does, but going by reftype... sigh...
336
337 for (values %$weak_registry) {
338 if ( my $r = reftype($_->{weakref}) ) {
339 $typecounts->{$r}--;
340 }
341 }
342
343 # For now we can only reuse the same registry, see FIXME above/below
344 #for my $interim_wr ({}, {}) {
345 for my $interim_wr ( ($weak_registry) x 4 ) {
346
347 visit_refs(
348 refs => [ $fire_resultsets->(), @rsets ],
349 action => sub {
350 populate_weakregistry ($interim_wr, $_[0]);
351 1; # true means "keep descending"
352 },
353 );
354
355 # FIXME - this is what *should* be here
356 #
357 ## anything we have seen so far is cool
358 #delete @{$interim_wr}{keys %$weak_registry};
359 #
6ae62c5c 360 ## moment of truth - the rest ought to be gone
361 #assert_empty_weakregistry($interim_wr);
362 }
363
364 for (values %$weak_registry) {
365 if ( my $r = reftype($_->{weakref}) ) {
366 $typecounts->{$r}++;
367 }
368 }
369 }
370
371 for (keys %$typecounts) {
372 fail ("Amount of $_ refs changed by $typecounts->{$_} during resultset mass-execution")
373 if ( abs ($typecounts->{$_}) > 1 ); # there is a pad caught somewhere, the +1/-1 can be ignored
374 }
21aa86aa 375 }
376
6a43bc0c 377 if ($has_dt) {
378 my $rs = $base_collection->{icdt_rs} = $schema->resultset('Event');
379
380 my $now = DateTime->now;
381 for (1..5) {
382 $base_collection->{"icdt_row_$_"} = $rs->create({
383 created_on => DateTime->new(year => 2011, month => 1, day => $_, time_zone => "-0${_}00" ),
384 starts_at => $now->clone->add(days => $_),
385 });
386 }
387
388 # re-search
389 my @dummy = $rs->all;
390 }
391
eb7aa960 392 # dbh's are created in XS space, so pull them separately
393 for ( grep { defined } map { @{$_->{ChildHandles}} } values %{ {DBI->installed_drivers()} } ) {
394 $base_collection->{"DBI handle $_"} = $_;
395 }
396
65d35121 397 populate_weakregistry ($weak_registry, $base_collection->{$_}, "basic $_")
398 for keys %$base_collection;
551e711a 399}
400
50261284 401# check that "phantom-chaining" works - we never lose track of the original $schema
402# and have access to the entire tree without leaking anything
403{
404 my $phantom;
405 for (
39b80a73 406 sub { DBICTest->init_schema( sqlite_use_file => 0 ) },
50261284 407 sub { shift->source('Artist') },
408 sub { shift->resultset },
409 sub { shift->result_source },
410 sub { shift->schema },
411 sub { shift->resultset('Artist') },
412 sub { shift->find_or_create({ name => 'detachable' }) },
413 sub { shift->result_source },
414 sub { shift->schema },
415 sub { shift->clone },
187ec69a 416 sub { shift->resultset('CD') },
417 sub { shift->next },
418 sub { shift->artist },
419 sub { shift->search_related('cds') },
50261284 420 sub { shift->next },
187ec69a 421 sub { shift->search_related('artist') },
50261284 422 sub { shift->result_source },
423 sub { shift->resultset },
424 sub { shift->create({ name => 'detached' }) },
425 sub { shift->update({ name => 'reattached' }) },
426 sub { shift->discard_changes },
427 sub { shift->delete },
428 sub { shift->insert },
429 ) {
65d35121 430 $phantom = populate_weakregistry ( $weak_registry, scalar $_->($phantom) );
50261284 431 }
432
433 ok( $phantom->in_storage, 'Properly deleted/reinserted' );
434 is( $phantom->name, 'reattached', 'Still correct name' );
435}
a8c2c746 436
307ab4c5 437# Naturally we have some exceptions
438my $cleared;
96577657 439for my $addr (keys %$weak_registry) {
440 my $names = join "\n", keys %{$weak_registry->{$addr}{slot_names}};
441
442 if ($names =~ /^Test::Builder/m) {
c8194884 443 # T::B 2.0 has result objects and other fancyness
96577657 444 delete $weak_registry->{$addr};
c8194884 445 }
96577657 446 elsif ($names =~ /^Hash::Merge/m) {
37aafa2e 447 # only clear one object of a specific behavior - more would indicate trouble
96577657 448 delete $weak_registry->{$addr}
449 unless $cleared->{hash_merge_singleton}{$weak_registry->{$addr}{weakref}{behavior}}++;
307ab4c5 450 }
e9d552de 451 elsif ($names =~ /^B::Hooks::EndOfScope::PP::_TieHintHashFieldHash/m) {
452 # there is one tied lexical which stays alive until GC time
453 # https://metacpan.org/source/ETHER/B-Hooks-EndOfScope-0.15/lib/B/Hooks/EndOfScope/PP/FieldHash.pm#L24
454 # simply ignore it here, instead of teaching the leaktracer to examine ties
455 # the latter is possible yet terrible: https://github.com/dbsrgits/dbix-class/blob/v0.082820/t/lib/DBICTest/Util/LeakTracer.pm#L113-L117
456 delete $weak_registry->{$addr}
457 unless $cleared->{bheos_pptiehinthashfieldhash}++;
458 }
3619783b 459 elsif ($names =~ /^DateTime::TimeZone::UTC/m) {
460 # DT is going through a refactor it seems - let it leak zones for now
461 delete $weak_registry->{$addr};
462 }
c0fe9332 463 elsif (
75c23ff0 464# # if we can look at closed over pieces - we will register it as a global
465# !DBICTest::Util::LeakTracer::CV_TRACING
466# and
c0fe9332 467 $names =~ /^SQL::Translator::Generator::DDL::SQLite/m
468 ) {
469 # SQLT::Producer::SQLite keeps global generators around for quoted
470 # and non-quoted DDL, allow one for each quoting style
471 delete $weak_registry->{$addr}
472 unless $cleared->{sqlt_ddl_sqlite}->{@{$weak_registry->{$addr}{weakref}->quote_chars}}++;
473 }
307ab4c5 474}
475
187ec69a 476# FIXME !!!
477# There is an actual strong circular reference taking place here, but because
5dc4301c 478# half of it is in XS, so it is a bit harder to track down (it stumps D::FR)
479# (our tracker does not yet do it, but it'd be nice)
480# The problem is:
187ec69a 481#
728f32b5 482# $cond_object --> result_source --> schema --> storage --> $dbh --> {CachedKids}
187ec69a 483# ^ /
484# \-------- bound value on prepared/cached STH <-----------/
485#
728f32b5 486{
5dc4301c 487 my @circreffed;
488
489 for my $r (map
490 { $_->{weakref} }
491 grep
492 { $_->{slot_names}{'basic leaky_resultset_cond'} }
493 values %$weak_registry
494 ) {
495 local $TODO = 'Needs Data::Entangled or somesuch - see RT#82942';
728f32b5 496 ok(! defined $r, 'Self-referential RS conditions no longer leak!')
5dc4301c 497 or push @circreffed, $r;
498 }
499
500 if (@circreffed) {
501 is (scalar @circreffed, 1, 'One resultset expected to leak');
502
503 # this is useless on its own, it is to showcase the circref-diag
504 # and eventually test it when it is operational
505 local $TODO = 'Needs Data::Entangled or somesuch - see RT#82942';
506 while (@circreffed) {
507 weaken (my $r = shift @circreffed);
508
509 populate_weakregistry( (my $mini_registry = {}), $r );
510 assert_empty_weakregistry( $mini_registry );
511
512 $r->result_source(undef);
513 }
728f32b5 514 }
187ec69a 515}
516
65d35121 517assert_empty_weakregistry ($weak_registry);
551e711a 518
66917da3 519# we got so far without a failure - this is a good thing
520# now let's try to rerun this script under a "persistent" environment
521# this is ugly and dirty but we do not yet have a Test::Embedded or
522# similar
523
7617dcc4 524my $persistence_tests;
66917da3 525SKIP: {
526 skip 'Test already in a persistent loop', 1
527 if $ENV{DBICTEST_IN_PERSISTENT_ENV};
528
66917da3 529 skip 'Main test failed - skipping persistent env tests', 1
530 unless $TB->is_passing;
531
ee20935b 532 skip "Test::Builder\@@{[ Test::Builder->VERSION ]} known to break persistence tests", 1
533 if modver_gt_or_eq_and_lt( 'Test::More', '1.200', '1.301001_099' );
534
66917da3 535 local $ENV{DBICTEST_IN_PERSISTENT_ENV} = 1;
536
7617dcc4 537 $persistence_tests = {
538 PPerl => {
539 cmd => [qw/pperl --prefork=1/, __FILE__],
540 },
541 'CGI::SpeedyCGI' => {
542 cmd => [qw/speedy -- -t5/, __FILE__],
543 },
544 };
545
546 # scgi is smart and will auto-reap after -t amount of seconds
547 # pperl needs an actual killer :(
548 $persistence_tests->{PPerl}{termcmd} = [
549 $persistence_tests->{PPerl}{cmd}[0],
550 '--kill',
551 @{$persistence_tests->{PPerl}{cmd}}[ 1 .. $#{$persistence_tests->{PPerl}{cmd}} ],
552 ];
553
4fb8d74c 554 # set up -I
555 require Config;
556 $ENV{PERL5LIB} = join ($Config::Config{path_sep}, @INC);
557
558 # adjust PATH for -T
559 if (length $ENV{PATH}) {
560 ( $ENV{PATH} ) = join ( $Config::Config{path_sep},
561 map { length($_) ? File::Spec->rel2abs($_) : () }
562 split /\Q$Config::Config{path_sep}/, $ENV{PATH}
563 ) =~ /\A(.+)\z/;
564 }
7be5717e 565
566 for my $type (keys %$persistence_tests) { SKIP: {
53a5200d 567 unless (eval "require $type") {
568 # Don't terminate what we didn't start
569 delete $persistence_tests->{$type}{termcmd};
570 skip "$type module not found", 1;
571 }
7be5717e 572
573 my @cmd = @{$persistence_tests->{$type}{cmd}};
66917da3 574
575 # since PPerl is racy and sucks - just prime the "server"
576 {
577 local $ENV{DBICTEST_PERSISTENT_ENV_BAIL_EARLY} = 1;
7be5717e 578 system(@cmd);
66917da3 579 sleep 1;
580
7be5717e 581 # see if the thing actually runs, if not - might as well bail now
582 skip "Something is wrong with $type ($!)", 1
583 if system(@cmd);
66917da3 584 }
585
4fb8d74c 586 require IPC::Open2;
587
66917da3 588 for (1,2,3) {
7be5717e 589 note ("Starting run in persistent env ($type pass $_)");
590 IPC::Open2::open2(my $out, undef, @cmd);
591 my @out_lines;
592 while (my $ln = <$out>) {
593 next if $ln =~ /^\s*$/;
594 push @out_lines, " $ln";
595 last if $ln =~ /^\d+\.\.\d+$/; # this is persistence, we need to terminate reading on our end
596 }
597 print $_ for @out_lines;
598 close $out;
599 wait;
600 ok (!$?, "Run in persistent env ($type pass $_): exit $?");
601 ok (scalar @out_lines, "Run in persistent env ($type pass $_): got output");
66917da3 602 }
603
7be5717e 604 ok (! system (@{$persistence_tests->{$type}{termcmd}}), "killed $type server instance")
605 if $persistence_tests->{$type}{termcmd};
606 }}
66917da3 607}
608
551e711a 609done_testing;
66917da3 610
611# just an extra precaution in case we blew away from the SKIP - since there are no
612# PID files to go by (man does pperl really suck :(
613END {
7617dcc4 614 if ($persistence_tests->{PPerl}{termcmd}) {
66917da3 615 local $?; # otherwise test will inherit $? of the system()
7617dcc4 616 require IPC::Open3;
617 open my $null, ">", File::Spec->devnull;
618 waitpid(
619 IPC::Open3::open3(undef, $null, $null, @{$persistence_tests->{PPerl}{termcmd}}),
620 0,
621 );
66917da3 622 }
623}