On Mon, Mar 18, 2002 at 02:45:33AM -0500, Mark-Jason Dominus wrote:
> 
> I've just found a bug in my module.  The bug results in an
> inappropriate infinite loop.
> 
> Before I fix the bug, I want to write up a test case.
> 
> I can reproduce the bug OK, but if I put that code into the module
> tests, and the bug isn't fixed, or comes back for some reason, then
> the test program will go into an infinite loop.
> 
> The test harness doesn't seem to notice that.  I don't want to go
> sticking code into my test files that might cause an infinite loop and
> hang up the test harness or the entire system.
> 
> If the module were for Unix only, I would stick an  'alarm 10' at the
> top of the test program.  I'm told this won't work under Win32.
> 
> What's the right way to handle this?

Use alarm and skip the test if $Config{d_alarm} is false (see
t/op/alarm.t for an example).  If you think the infinite loop is due
to a programming glitch, as opposed to a cross-platform issue, this
will be enough.


The only other thing I can think of is to set up a parent process
which forks off a child and kills it if its still going after 10
seconds.  That gets into fork(), which is even less portable than
alarm.  Checking to see if Win32 can pseudo-fork is a little more
complicated than alarm (see t/op/fork.t).

If you provide both methods you can cover Unix, Win32 and a bunch of
other platforms.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
"What's black and white and makes you duck as it goes by?"
"A nun with a spear through her head."

Reply via email to