From 0af4a558da35a76e769a02ef3a8f736ed6744394 Mon Sep 17 00:00:00 2001
From: George Joseph <gjoseph@digium.com>
Date: Tue, 17 Jul 2018 03:03:02 -0600
Subject: [PATCH] CI: Add teardownRealtime

Change-Id: I2fe55c38607eaec2fbf69ef23a5019e0c443a64b
---
 tests/CI/runTestsuite.sh     | 4 ++++
 tests/CI/setupRealtime.sh    | 4 +++-
 tests/CI/teardownRealtime.sh | 6 ++++++
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100755 tests/CI/teardownRealtime.sh

diff --git a/tests/CI/runTestsuite.sh b/tests/CI/runTestsuite.sh
index 35f4d58948..9261308299 100755
--- a/tests/CI/runTestsuite.sh
+++ b/tests/CI/runTestsuite.sh
@@ -16,6 +16,10 @@ export PYTHONPATH=./lib/python/
 echo "Running tests ${TEST_COMMAND}"
 ./runtests.py --cleanup ${TEST_COMMAND} | contrib/scripts/pretty_print --no-color --no-timer --term-width=120 --show-errors || :
 
+if [ $REALTIME -eq 0 ] ; then
+	$CIDIR/teardownRealtime.sh
+fi
+
 if [ -f core* ] ; then
 	echo "*** Found a core file after running unit tests ***"
 	/var/lib/asterisk/scripts/ast_coredumper --no-default-search core*
diff --git a/tests/CI/setupRealtime.sh b/tests/CI/setupRealtime.sh
index 01593a1060..f599d335e0 100755
--- a/tests/CI/setupRealtime.sh
+++ b/tests/CI/setupRealtime.sh
@@ -4,7 +4,9 @@ source $CIDIR/ci.functions
 
 set -e
 
-cat >test-config.yaml <<EOF
+cp test-config.yaml test-config.orig.yaml
+
+cat >test-config.yaml <<-EOF
 	global-settings:
 	    test-configuration: config-realtime
 
diff --git a/tests/CI/teardownRealtime.sh b/tests/CI/teardownRealtime.sh
new file mode 100755
index 0000000000..11146990ff
--- /dev/null
+++ b/tests/CI/teardownRealtime.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+CIDIR=$(dirname $(readlink -fn $0))
+source $CIDIR/ci.functions
+
+cp test-config.orig.yaml test-config.yaml
+psql --username=asterisk --host=localhost --db=asterisk --command='DROP OWNED BY asterisk CASCADE'
-- 
GitLab