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