[monitoring-plugins] check_procs: Add delay after forking in test

Mikael Falkvidd git at monitoring-plugins.org
Thu Jul 10 21:30:10 CEST 2014


 Module: monitoring-plugins
 Branch: master
 Commit: f54d10fe9ba202415c2001b1ec7c6eb4697c3d10
 Author: Mikael Falkvidd <mfalkvidd at op5.com>
   Date: Thu Jul 10 14:25:23 2014 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=f54d10f

check_procs: Add delay after forking in test

Forking raises a race condition, where the parent might run the
test before the child has had time to fork. If that happens,
an error similar to this is produced:
 Failed test 'Output correct'
 at ./t/check_procs.t line 32.
                 'PROCS OK: 0 processes with args 'sleep 7' | processes=0;;;0;'
   doesn't match '/^PROCS OK: 1 process?/'

Sleeping a bit should avoid the problem. It might be enough to
sleep less than a second, but perl's built-in sleep function only
supports integer seconds.

In our build environment, the build failed 3 of 4 times before
this patch. After the patch it failed 0 of 7 times.

Signed-off-by: Mikael Falkvidd <mfalkvidd at op5.com>

---

 plugins/t/check_procs.t | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t
index ca4acdd..abe7284 100644
--- a/plugins/t/check_procs.t
+++ b/plugins/t/check_procs.t
@@ -26,7 +26,7 @@ $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
 is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
 like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
 
-if(fork() == 0) { exec("sleep 7"); } # fork a test process
+if(fork() == 0) { exec("sleep 7"); } else { sleep(1) } # fork a test process in child and give child time to fork in parent
 $result = NPTest->testCmd( "./check_procs -a 'sleep 7'" );
 is( $result->return_code, 0, "Parent process is ignored" );
 like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );



More information about the Commits mailing list