diff options
author | Mikael Falkvidd <mfalkvidd@op5.com> | 2014-07-10 14:25:23 +0200 |
---|---|---|
committer | Mikael Falkvidd <mfalkvidd@op5.com> | 2014-07-10 21:10:48 +0200 |
commit | f54d10fe9ba202415c2001b1ec7c6eb4697c3d10 (patch) | |
tree | 4d158b23339b383c374ab3ad43072e6d9999c8b0 /plugins/t | |
parent | 43b66c06a921b878ba4de2a246a219cca94dd498 (diff) | |
download | monitoring-plugins-f54d10fe9ba202415c2001b1ec7c6eb4697c3d10.tar.gz |
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@op5.com>
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_procs.t | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t index ca4acdd7..abe7284e 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" ); | |||
26 | is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); | 26 | is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); |
27 | like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" ); | 27 | like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" ); |
28 | 28 | ||
29 | if(fork() == 0) { exec("sleep 7"); } # fork a test process | 29 | if(fork() == 0) { exec("sleep 7"); } else { sleep(1) } # fork a test process in child and give child time to fork in parent |
30 | $result = NPTest->testCmd( "./check_procs -a 'sleep 7'" ); | 30 | $result = NPTest->testCmd( "./check_procs -a 'sleep 7'" ); |
31 | is( $result->return_code, 0, "Parent process is ignored" ); | 31 | is( $result->return_code, 0, "Parent process is ignored" ); |
32 | like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" ); | 32 | like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" ); |