Recently a race condition was found in a application I am responsible for, this application actually is a custom XML RPC engine... what happens is 2 exact requests come in at same time, the first one comes back with the correct response, the second one throws a error.

The reason for the error is simply not using transactions in the DB so they are both trying to update at same time and its failing, this I know how to fix... but my question is how do I add test cases for it

Reason I ask that is my test suite is a series of sequential tests, ok(x);ok(y); etc - however to simulate this I need to find a way of effectively simulating the race condition within the test script so thus firing off the same time almost in parallel... but whats the best way of doing this ? I could use fork but that does seem overkill in a test script... I could ignore testing this scenario... but seeing as the tests I have written are my best friend I am sure there must be a better way ? any ideas welcome...


In reply to Testing Race Conditions by ropey

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.