ctdb-tests: Add handling of process clean-up on a cluster node
authorMartin Schwenke <martin@meltin.net>
Sat, 28 Sep 2019 22:27:33 +0000 (08:27 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 24 Oct 2019 04:06:44 +0000 (04:06 +0000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/scripts/integration.bash

index bbb3a64ea5a6ef3b266b46e0b866e9695706dcab..d5bd542ab00c30aeecbc23eac02e2447c60b425a 100644 (file)
@@ -60,6 +60,34 @@ ctdb_test_exit_hook_add ()
     ctdb_test_exit_hook="${ctdb_test_exit_hook}${ctdb_test_exit_hook:+ ; }$*"
 }
 
+# Setting cleanup_pid to <pid>@<node> will cause <pid> to be killed on
+# <node> when the test completes.  To cancel, just unset cleanup_pid.
+ctdb_test_cleanup_pid=""
+ctdb_test_cleanup_pid_exit_hook ()
+{
+       if [ -n "$ctdb_test_cleanup_pid" ] ; then
+               local pid="${ctdb_test_cleanup_pid%@*}"
+               local node="${ctdb_test_cleanup_pid#*@}"
+
+               try_command_on_node "$node" "kill ${pid}"
+       fi
+}
+
+ctdb_test_exit_hook_add ctdb_test_cleanup_pid_exit_hook
+
+ctdb_test_cleanup_pid_set ()
+{
+       local node="$1"
+       local pid="$2"
+
+       ctdb_test_cleanup_pid="${pid}@${node}"
+}
+
+ctdb_test_cleanup_pid_clear ()
+{
+       ctdb_test_cleanup_pid=""
+}
+
 ctdb_test_init ()
 {
        trap "ctdb_test_exit" 0