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.
curl_put /profile "{ \"nickname\": \"$player\" }" "-c ${!player_cookie}"
empathy_get $player events >/dev/null 2>&1 &
eval ${player_pid}=$!
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>
}
# Usage: empathy_player_deactivate <player_name>
{
player="$1"
player_pid=${player}_pid
{
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
}
# Pulls a single named event out of the empathy event stream
test "$result" = '"alice" 1 "bob" 1 "charlie" 0'
TEST_END
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