docker: make sure to cleanup containers before force exit
Observed containers were being left over on the host machine when
docker tests were terminated mid way. Due to this, host machine was not
able to run anymore containers after a certain threshold of running
containers and eventually runs out of available memory. Fix this issue
by always cleaning the containers when exiting from the tests.
Change-Id: I85429ab52172dbeb9a6b87b49daee43dc26cc47d
diff --git a/test/docker/run.sh b/test/docker/run.sh
index b1acf87..a57780b 100755
--- a/test/docker/run.sh
+++ b/test/docker/run.sh
@@ -85,8 +85,7 @@
usage "$MISSING, did you forget --task-plugin-jar?"
fi
[ -n "$GERRIT_WAR" ] && cp -f "$GERRIT_WAR" "$ARTIFACTS/gerrit.war"
-progress "Building docker images" build_images
-run_task_plugin_tests ; RESULT=$?
-cleanup
-
-exit "$RESULT"
+( trap cleanup EXIT SIGTERM
+ progress "Building docker images" build_images
+ run_task_plugin_tests
+)