<html><body>On 08:00 pm, exarkun@divmod.com wrote:<br />&gt;On Fri, 12 Jan 2007 10:54:10 -0800, Scott Lamb &lt;slamb@slamb.org&gt; wrote:<br /><br />&gt;&gt;(1) create a test that likely fails by running many, many times. It'd &#160;bog <br />&gt;&gt;down the test suite.<br />&gt;&gt;(2) create a test that might fail sometime, maybe.<br />&gt;&gt;(3) add instrumentation to the main code solely for the purpose of &#160;the <br />&gt;&gt;test (break twisted's kneecap before the race).<br />&gt;&gt;(4) just say "clearly[*] if event A happens between lines X and Y, &#160;then it <br />&gt;&gt;is handled improperly."<br />&gt;&gt;<br />&gt;&gt;I prefer #4.<br />&gt;<br />&gt;I think this actually varies from case to case. &#160;For a problem where all<br />&gt;of the relevant critical points cannot be hooked or mocked or stubbed or<br />&gt;what have you, then a combination of #2 and #4 seems correct to me. &#160;You<br />&gt;should be able to demonstrate that a real problem does exist by adding a<br />&gt;test which will fail eventually when run repeatedly (eg, using trial -u)<br />&gt;and which runs for orders of magnitude longer without failing once a fix<br />&gt;has been applied.<br /><br />Race conditions are tricky, but in every case it is worth _trying_ to mock/stub/hook the code as it already is to demonstrate it deterministically. &#160;It isn't always possible with a reasonable amount of effort, but very often it is actually quite easy. &#160;As you do it more, it gets easier to figure out the trickier cases.<br /><br />In any case, writing a test (which runs quickly) to be used with trial -u is a pretty low bar. &#160;There are some extremely rare cases (mostly involving threading infrastructure) where those tests take a long time to fail, but even there it is usually possible to make them *succeed* reliably.<br /><br />&gt;Always feel free to file the ticket before figuring any of this out, by<br />&gt;the way. &#160;It is still possible that it will strike someone else's fancy<br />&gt;and the rest of the work will be taken care of for you. :)<br /><br />And of course this is always true.<br /></body></html>