From: Carl Worth Date: Sat, 27 Jun 2020 15:43:28 +0000 (-0700) Subject: test: Maintain a list of activated players for automated cleanup X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=ea2ea3dbf1184f5e21b3a9ead6dfec337710d18a test: Maintain a list of activated players for automated cleanup 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. --- diff --git a/test b/test index 5671aff..4cdeb89 100755 --- 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 @@ -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