I recently had to deal with a bug where under certain circumstances a server process would never terminate, but would block indefinitely in the shutdown process. Being a good coder, I wrote a unit test to reproduce the problem before I fixed it. The test is happy when I run it normally, and even when I run it under Devel::Cover, but it consistently fails in our nightly test run (under Devel::Cover). As best I can figure, Devel::Cover is slowing things down so much that my test thinks the process doesn't exit.

Here's what the test looks like:


if (my $pid = fork) { eval 'use Test::More qw(no_plan)'; sleep 1;

  # interact with server (child process)
  # ...
        
  kill TERM => $pid;

  my $kid;  my $c = 0;
  while (($kid = waitpid($pid, WNOHANG)) == 0) {
    last if $c > 10;  # really long because Devel::Cover is slooooow!
    sleep 1;
    $c++;
  }

  if ($kid > 0) {
    if ($?) {
      fail("Child died with $?\n");
    } else {
      pass("Child exited");
    }
  } else {
    fail("Child did not exit");
    kill 9 => $pid;
  }

} else {
   # run server process
}


So, as you can see, I interact with the child process in a way to tickle the bug, then send it a shutdown signal, then wait for 10 seconds for it to terminate. Unfortunately, it's seeming like even 10 seconds is not enough sometimes.


Does anyone have a suggestion of how else to do this type of test? Is there some good way that I could figure out if the process is blocking indefinitely or just running the shutdown very slowly?



Thanks,

Kevin



Reply via email to