diff mbox series

[ovs-dev] tests: Kill the daemons at cleanup only if pidfile exists.

Message ID 20171222151252.9664-1-jkbs@redhat.com
State Accepted
Headers show
Series [ovs-dev] tests: Kill the daemons at cleanup only if pidfile exists. | expand

Commit Message

Jakub Sitnicki Dec. 22, 2017, 3:12 p.m. UTC
Remembering the PIDs of started daemon processes and killing them during
cleanup can interfere with other tests.

When the tests are running in parallel (i.e., -jX was passed in
TESTSUITEFLAGS), PIDs of daemons that have terminated before the cleanup
are subject to reuse by processes, or threads, spawned in another test.

This means that, while executing its 'cleanup' script, one test can
accidentally send a SIGTERM to a process running as a part of another
test and influence its outcome.

Retrieve the PID of the process we intend to kill at the last possible
moment to narrow down the window of opportunity for interfering.

This approach has a downside that if the daemon's pidfile has
disappeared but the process has not terminated, we will not clean it up
at the end of the test.

Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>
---
 tests/ofproto-macros.at | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ben Pfaff Dec. 26, 2017, 5:44 p.m. UTC | #1
On Fri, Dec 22, 2017 at 04:12:52PM +0100, Jakub Sitnicki wrote:
> Remembering the PIDs of started daemon processes and killing them during
> cleanup can interfere with other tests.
> 
> When the tests are running in parallel (i.e., -jX was passed in
> TESTSUITEFLAGS), PIDs of daemons that have terminated before the cleanup
> are subject to reuse by processes, or threads, spawned in another test.
> 
> This means that, while executing its 'cleanup' script, one test can
> accidentally send a SIGTERM to a process running as a part of another
> test and influence its outcome.
> 
> Retrieve the PID of the process we intend to kill at the last possible
> moment to narrow down the window of opportunity for interfering.
> 
> This approach has a downside that if the daemon's pidfile has
> disappeared but the process has not terminated, we will not clean it up
> at the end of the test.
> 
> Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>

Applied to master, thanks!
diff mbox series

Patch

diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index 64cba44..ec5c892 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -55,8 +55,8 @@  m4_define([PARSE_LISTENING_PORT],
 
 start_daemon () {
     "$@" -vconsole:off --detach --no-chdir --pidfile --log-file
-    pid=`cat "$OVS_RUNDIR"/$1.pid`
-    on_exit "kill $pid"
+    pidfile="$OVS_RUNDIR"/$1.pid
+    on_exit "test -e \"$pidfile\" && kill \`cat \"$pidfile\"\`"
 }
 
 # sim_add SANDBOX