From: Peter Rabbitson Date: Wed, 7 Oct 2015 11:39:46 +0000 (+0200) Subject: Reduce amount of initial connects during non-SQLite test-RDBMS lock-grabs X-Git-Tag: v0.082821~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=62cf2c2af2e4d6825fd719e05ba7ba44dc91401b Reduce amount of initial connects during non-SQLite test-RDBMS lock-grabs I am not sure why I wrote things this way back in 8d6b1478d, perhaps I didn't properly think through that sqlt_type will be correctly determined no matter what. As a result any MySQL test would connect at least once, and under the right circumstances consume enough per-connection-thread memory to get a low-RAM system (like TravisCI) to start OOM-killing things indiscriminately. --- diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index cdc7a02..82e4dd9 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -156,28 +156,28 @@ sub connection { ($_[0]||'') !~ /^ (?i:dbi) \: SQLite \: (?: dbname\= )? (?: \:memory\: | t [\/\\] var [\/\\] DBIxClass\-) /x ) { - my $locktype = do { + my $locktype; + + { # guard against infinite recursion local $ENV{DBICTEST_LOCK_HOLDER} = -1; - # we need to connect a forced fresh clone so that we do not upset any state + # we need to work with a forced fresh clone so that we do not upset any state # of the main $schema (some tests examine it quite closely) local $SIG{__WARN__} = sub {}; local $@; - my $storage = eval { - my $st = ref($self)->connect(@{$self->storage->connect_info})->storage; - $st->ensure_connected; # do connect here, to catch a possible throw - $st; + + # this will either give us an undef $locktype or will determine things + # properly with a default ( possibly connecting in the process ) + eval { + my $s = ref($self)->connect(@{$self->storage->connect_info})->storage; + + $locktype = $s->sqlt_type || 'generic'; + + # in case sqlt_type did connect, doesn't matter if it fails or something + $s->disconnect; }; - $storage - ? do { - my $t = $storage->sqlt_type || 'generic'; - eval { $storage->disconnect }; - $t; - } - : undef - ; - }; + } # Never hold more than one lock. This solves the "lock in order" issues # unrelated tests may have