Cleanup the event capturing for diffs

Since there are several different types of captures happening in the
tests, qualify the methods which are related to the diffs. Also
explicitly cleanup the diff captures once the results have been
processed so that the resources are released before running any tests
which may be added after the diff (such as filtered event tests).
Finally, make it a bit clearer to which tests the diffs are intending to
applied to by starting the captures inside the specific test GROUP which
will be diffed.

Change-Id: I5bc8a95e24a84ab23c7f46a2824bea5f9a1d0121
diff --git a/test/test_events_plugin.sh b/test/test_events_plugin.sh
index 6d88db9..da8cb33 100755
--- a/test/test_events_plugin.sh
+++ b/test/test_events_plugin.sh
@@ -9,7 +9,7 @@
 
 cleanup() {
     wait_event
-    (kill_captures ; sleep 1 ; kill_captures -9 ) &
+    (kill_diff_captures ; sleep 1 ; kill_diff_captures -9 ) &
 }
 
 # > uuid
@@ -99,14 +99,14 @@
 
 # ------------------------- Event Capturing ---------------------------
 
-kill_captures() { # sig
+kill_diff_captures() { # sig
     local pid
     for pid in "${CAPTURE_PIDS[@]}" ; do
         q kill $1 $pid
     done
 }
 
-setup_captures() {
+setup_diff_captures() {
     ssh -p 29418 -x "$SERVER" "${CORE_CMD[@]}" > "$EVENTS_CORE" &
     CAPTURE_PIDS=("${CAPTURE_PIDS[@]}" $!)
     ssh -p 29418 -x "$SERVER" "${PLUGIN_CMD[@]}" > "$EVENTS_PLUGIN" &
@@ -226,8 +226,6 @@
 
 trap cleanup EXIT
 
-setup_captures
-
 # We need to do an initial REST call, as the first REST call after a server is
 # brought up results in being anonymous despite providing proper authentication.
 get_open_changes
@@ -236,6 +234,8 @@
 
 # ------------------------- Individual Event Tests ---------------------------
 GROUP=visible-events
+setup_diff_captures
+
 type=patchset-created
 capture_events 3
 ch1=$(create_change "$REF_BRANCH" "$FILE_A") || exit
@@ -286,9 +286,9 @@
 
 # reviewer-added needs to be tested via Rest-API
 
-# ------------------------- Compare them all to Core -------------------------
-
 out=$(diff -- "$EVENTS_CORE" "$EVENTS_PLUGIN")
-result "core/plugin diff" "$out"
+result "$GROUP core/plugin diff" "$out"
+
+kill_diff_captures
 
 exit $RESULT