]> git.cworth.org Git - empires-server/commitdiff
test: Maintain a list of activated players for automated cleanup
authorCarl Worth <cworth@cworth.org>
Sat, 27 Jun 2020 15:43:28 +0000 (08:43 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 27 Jun 2020 15:43:28 +0000 (08:43 -0700)
The list of deactivate calls at the end of the test sutie was getting
rather messy, (since it required awareness of which players had been
activated in specific tests and then also which had _not_ been
deactivated in other tests).

Instead, we now store an array of each activated player, and loop over
that deactivating all players at the end. We also make deactivate
idempotent, safely doing nothing if we ask to deactivate a plyer which
was already deactivated.

test

diff --git a/test b/test
index 5671affacf3b7c7c29d3ae87fccbb07432fffc9d..4cdeb895991e6122379b0d412d527997963aa838 100755 (executable)
--- a/test
+++ b/test
@@ -467,6 +467,7 @@ empathy_player_activate()
     curl_put /profile "{ \"nickname\": \"$player\" }" "-c ${!player_cookie}"
     empathy_get $player events >/dev/null 2>&1 &
     eval ${player_pid}=$!
+    empathy_players+=($player)
 }
 
 # Usage: empathy_player_deactivate <player_name>
@@ -474,7 +475,10 @@ empathy_player_deactivate()
 {
     player="$1"
     player_pid=${player}_pid
-    pkill -P ${!player_pid}
+    if [ "${!player_pid}" != "" ]; then
+        pkill -P ${!player_pid}
+    fi
+    eval ${player_pid}=""
 }
 
 # Pulls a single named event out of the empathy event stream
@@ -895,8 +899,13 @@ result=$(echo $(empathy_scores_names_numbers alice))
 test "$result" = '"alice" 1 "bob" 1 "charlie" 0'
 TEST_END
 
-empathy_player_deactivate alice
-empathy_player_deactivate bob
-empathy_player_deactivate charlie
+empathy_deactivate_all()
+{
+    for player in ${empathy_players[*]}; do
+        empathy_player_deactivate $player
+    done
+}
+
+empathy_deactivate_all
 
 TEST_REPORT