Learned brothers, I have a question:

I am working on an application that uses DBIx::Class to store it's data. There are around 100 tables, with plenty of joins and other relationships between the various tables. It is a complicated beast.

As with any large project, I have a number of tests. Most of them work by starting with an empty copy of the database, populating a small number of tables with a small amount of data, and then testing that the API calls retrieve the expected data. For example:

use strict; use warnings; use Test::More tests => 134; use My::Company::Schema; # Creates an empty SQLite DB in memory and deploys the schema to it. my $schema = My::Company::Schema->connect; # set-up some test data my $tblFoo = $schema->resultset('Foo'); my $foo_item_1 = $tblFoo->create({ name => 'item1', # Other fields }); my $foo_item_2 = $tblFoo->create({ name => 'item2', # More fields }); my $bar_item = $foo_item_2->add_to_relation({'key'=>'value'}); # More code to populate the test DB. # Tests: my $found_entry_foo = $tblFoo_rs->big_complex_api_call(); is( $found_entry_foo->id, $bar_item->id, "The correct entry from tblFo +o was found" );

The problem is, is that test above contains a bug. On the last line the primary key of the returned row is compared with the expected value from the WRONG table. The idiom is used in thousands of tests, and I have a nasty feeling that the wrong comparisons are done in quite a few places.

The reason the bug goes un-detected, is that the test tables only contain a few rows, and the numeric primary keys start from 1, and number incrementally, so there is a good chance that row 2 in one table could get confused with row 2 in another.

Is there an extension, or directive I can give to DBIx::Class, that will cause it to start the numbering of primary keys from a random large number, in order to flush out bugs like this? I did not find anything from reading the DBIx::Class docs, or from Google, though I could be looking in the wrong place.


In reply to DBIx::Class Randomise datbase primary keys for testing. by chrestomanci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.