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