Bug#665221: libdancer-plugin-database-perl: FTBFS: tests failed

Niko Tyni ntyni at debian.org
Sat Mar 31 07:46:37 UTC 2012


tag 665221 - moreinfo unreproducible
tag 665221 + upstream
forwarded 665221 https://github.com/bigpresh/Dancer-Plugin-Database/issues/29
thanks

On Thu, Mar 22, 2012 at 05:34:55PM +0100, Lucas Nussbaum wrote:
> Source: libdancer-plugin-database-perl
> Version: 1.81-1
> Severity: serious
> Tags: wheezy sid
> User: debian-qa at lists.debian.org
> Usertags: qa-ftbfs-20120321 qa-ftbfs
> Justification: FTBFS on amd64

> > #   Failed test 'database_connection_failed hook fires'
> > #   at t/01-basic.t line 155.
> > #          got: ''
> > #     expected: '1'
> > # Looks like you failed 1 test of 41.

This one is quite a heisenbug. Fortunately it's reproducible
here with 'make test' (but not with 'prove -b t/*.t').

The problem is in using of argument hashref stringification as
a database handle index in Dancer::Plugin::Database::database().
Quoting some comments in the code:

  # Hashref used as key for default handle, so we don't have a magic value that
  # the user could use for one of their connection names and cause problems
  # (Kudos to Igor Bujna for the idea)
  [...]
    # The key to use to store this handle in %handles.  This will be either the
    # name supplied to database(), the hashref supplied to database() (thus, as
    # long as the same hashref of settings is passed, the same handle will be
    # reused) or $def_handle if database() is called without args:
  [...]
    # Accept a hashref of settings to use, if desired.  If so, we use this
    # hashref to look for the handle, too, so as long as the same hashref is
    # passed to the database() keyword, we'll reuse the same handle:

This fails when memory is reused so that a different argument hash gets
the same memory address and hence the same stringification.

Adding this instrumentation into Database.pm:60 or thereabouts:

 use Data::Dumper;
 my $new = Dumper($handle_key);

 if (exists $strings{$handle_key}) {
     my $old = $strings{$handle_key};
     warn "hashref collision: $old vs. $new" if $old ne $new;
 }
 $strings{$handle_key} = $new;

gives this output when the test fails:

   t/01-basic.t ...... 40/41 hashref collision: $VAR1 = {
             'database' => ':memory:',
             'driver' => 'SQLite'
           };
    vs. $VAR1 = {
             'dsn' => 'dbi:SQLite:/Please/Tell/Me/This/File/Does/Not/Exist!',
             'dbi_params' => {
                               'HandleError' => sub { "DUMMY" },
                               'RaiseError' => 0,
                               'PrintError' => 0
                             }
           };
   
   #   Failed test 'database_connection_failed hook fires'
   #   at t/01-basic.t line 155.
   #          got: ''
   #     expected: '1'
   # Looks like you failed 1 test of 41.
   
which clearly shows the problem: the test is making sure that a
nonexistent database can't be opened, but the code is reusing a handle
for an in-memory database that's working fine.

I'm attaching a test script that should demonstrate this
in a reproducible way.

I suppose the handle index should include a serialization of the
arguments.  However, I'm afraid that's hard to do for the general case
as they may include code references (like the 'HandleError' subroutine
above).

I've forwarded this upstream as 
 <https://github.com/bigpresh/Dancer-Plugin-Database/issues/29>.
-- 
Niko Tyni   ntyni at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 03-serial.t
Type: application/x-troff
Size: 760 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/attachments/20120331/5eb82ced/attachment.t>


More information about the pkg-perl-maintainers mailing list