#
#
# ./mg-schema-test-database create [_SUFFIX] [TASK...] \
-# [-fMINFLIGHT | -f-NUMFLIGHTS]
+# [-fMINFLIGHT | -f-NUMFLIGHTS] \
+# [-hCTRL_DAEMONS_HOST] [-fOWNER_D_PORT[,QUEUE_D_PORT]]
#
# does `drop' and then creates
# - the database osstestdb_test_SUFFIX
# TASKs become idle in the test copy. Others become allocated to
# a specially-created `owned by someone in real db' task.
#
+# Default for CTRL_DAEMONS_HOST is localhost; if no port is supplied,
+# we use the corresponding production port + 2; if only one port is
+# supplied we use that and the next port number.
+#
#
# ./mg-schema-test-database drop [_SUFFIX]
#
# deletes your test database and removes the local-config file
#
#
+# ./mg-schema-test-database daemons [_SUFFIX]
+#
+# synchronously runs owner and queue daemons for your test database
+#
+# NB that you can't drop a test database with these daemons running,
+# because Postgres will refuse to drop a database that anyone is
+# connected to.
+
set -e -o posix ${OSSTEST_DEBUG:+-x}
}
withtest () {
+ if ! [ -e "$tcfg" ]; then
+ fail "test $dbname not set up ($tcfg does not exist)"
+ fi
OSSTEST_CONFIG="$test_cfg_setting" "$@"
}
;;
-f*) minflight="${arg#-f}"
;;
+ -h*) ctrlhost="${arg#-h}"
+ ;;
+ -p*) ctrlports="${arg#-p}"
+ ;;
*) fail "bad arg to create"
;;
esac
;;
esac
+ if [ "x$ctrlhost" = x ]; then
+ ctrlhost=localhost
+ fi
+ case "$ctrlports" in
+ *,*) ;;
+ ?*) ctrlports+=,$(( $ctrlports + 1 )) ;;
+ '')
+ ctrlports=$(( $(getconfig OwnerDaemonPort) + 2)),$((
+ $(getconfig QueueDaemonPort) + 2))
+ ;;
+ esac
+
#---------- preparation and data-gathering ----------
bad=$( psql_query <<END
printf "Setting up %s (minflight=%d, tasks=%s)...\n" \
$dbname "$minflight" "${tasks# }"
+ printf "Configuring for any daemons to be on %s:%s.\n" \
+ $ctrlhost $ctrlports
# create the config overlay
perl >$tcfg.tmp -we '
"port=$dbh_tests->{pg_port}\n"
or die $!;
'
+ cat >>$tcfg.tmp <<END
+OwnerDaemonHost $ctrlhost
+QueueDaemonHost $ctrlhost
+OwnerDaemonPort ${ctrlports%,*}
+QueueDaemonPort ${ctrlports#*,}
+END
mv -f $tcfg.tmp $tcfg
# Extract the schema for reference
;;
+#========== DAEMONS ==========
+
+daemons)
+ parse_only_suffix "$@"
+
+ dbname
+
+ printf "Running daemons for %s....\n" "$dbname"
+
+ withtest \
+ exec_resetting_sigint ./ms-ownerdaemon &
+
+ sleep 1
+
+ withtest \
+ exec_resetting_sigint ./ms-queuedaemon &
+
+ wait
+
+ ;;
+
#========== EPILOGUE ==========
*)