[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.contrib.usher: eab043a0c4ce
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.contrib.usher: eab043a0c4ceb4bdfc8c8897dfc4b96b7e3c2df2 |
Date: |
Tue, 22 Feb 2011 18:43:03 +0100 (CET) |
revision: eab043a0c4ceb4bdfc8c8897dfc4b96b7e3c2df2
date: 2011-02-22T17:42:51
author: Richard Levitte <address@hidden>
branch: net.venge.monotone.contrib.usher
changelog:
Make the tests do another round with projects controlled with usherctl.
* test/test2/databases.txt, test/test2/keys.txt, test/test2/projects.txt,
test/test2/script.txt: New files that describe how to set up and test.
* test/populate-branch.sh: Change so the database doesn't have to reside
in the database/ directory.
* test/run-tests.sh (populate): Prefix the given database with database/.
(usherctl_populate): Added function to populate databases controlled
with usherctl.
(create_client_key): Added function to create new client keys on the
fly. Used with the test based on usherctl.
(usherctl_mkproject): Added function to create projects with usherctl.
(client): Modified to be able to handle a specifically given key, and
to handle cases where the client is supposed to fail.
(multipull): Modified to be able to handle a specifically given key.
(wait_for_clients): Added an extra loop to wait for clients that are
supposed to fail. The condition to set OK to false is, of course,
different.
[main]: It's now possible to give the tests to run with this scripts on
the command line. It's also been modified to handle a usherctl based
structure and to handle XFAIL cases (script lines that start with '! ').
manifest:
format_version "1"
new_manifest [26b7fbe9d4a4610285236dc869fb09e791f77533]
old_revision [38107f35dfdfb90a8f8aaa118f205e8131cc31dc]
add_dir "test/test2"
add_file "test/test2/databases.txt"
content [26306a8d15153631a69ebbab8a33fcac411d3d99]
add_file "test/test2/keys.txt"
content [d5f519273d6c1f9edbd02fa654774d47ce6ec3cb]
add_file "test/test2/projects.txt"
content [d23a983e3ae7ea2a13e9e6159d114e574d995ab9]
add_file "test/test2/script.txt"
content [90c8fbd0cb741592730841c1e3ba4c41ea4a1f47]
patch "test/populate-branch.sh"
from [56f9bb64ce5fc0fd841b146d070ebd9c6e07c66c]
to [e231025582932ad39cb2137a8f543aef582010a4]
patch "test/run-tests.sh"
from [0773db5606bbdaab16b1708ad9210c6f4f5d48d4]
to [ce9093f286b75c23a7373a23fffd3fdf52b795e6]
============================================================
--- test/populate-branch.sh 56f9bb64ce5fc0fd841b146d070ebd9c6e07c66c
+++ test/populate-branch.sh e231025582932ad39cb2137a8f543aef582010a4
@@ -17,7 +17,7 @@ fi
$mtn au generate_key address@hidden address@hidden
fi
-$mtn -d databases/$database setup -b $branch $branch
+$mtn -d $database setup -b $branch $branch
pick_file() {
local files=$(ls | grep -v _MTN | wc -l)
============================================================
--- test/run-tests.sh 0773db5606bbdaab16b1708ad9210c6f4f5d48d4
+++ test/run-tests.sh ce9093f286b75c23a7373a23fffd3fdf52b795e6
@@ -6,17 +6,68 @@ populate() {
populate() {
echo "$@" >&2
- local database=$1
+ local database=databases/$1
local branch=$2
local count=$3
- if ! [ -e databases/$database.mtn ]; then
- mtn -d databases/$database.mtn db init
+ if ! [ -e $database.mtn ]; then
+ mtn -d $database.mtn db init
fi
if [ ! $count ] || [ $count -gt 0 ]; then
$SRCDIR/test/populate-branch.sh $database.mtn $branch $count
fi
}
+usherctl_populate() {
+ echo "$@" >&2
+ local type="$1"
+ local database=
+ case "$type" in
+ project )
+ database="`$USHERCTL info $2 -d | sed -e 's/.*: *//' -e 's/\.mtn$//'`"
+ ;;
+ database )
+ database="databases/$2"
+ if ! [ -e $database.mtn ]; then
+ mtn -d $database.mtn db init
+ fi
+ ;;
+ esac
+ local branch="$3"
+ local count="$4"
+ if [ ! $count ] || [ $count -gt 0 ]; then
+ $SRCDIR/test/populate-branch.sh $database.mtn $branch $count
+ fi
+}
+
+create_client_key() {
+ local name="$1"
+ (echo; echo) | mtn --keydir ./keys genkey "$name"
+}
+
+usherctl_mkproject() {
+ local type="$1"; shift
+ local servername="$1"; shift
+ local hostname="$1"; shift
+ local pattern="$1"; shift
+ case $type in
+ priv | pub )
+ (
+ set -e
+ $USHERCTL mk${type}project "$servername"
+ $USHERCTL addpattern "$servername" "$pattern*"
+ while [ $# -gt 0 ]; do
+ mtn --keydir ./keys automate get_public_key `echo $1 | cut -f2 -d:` | \
+ $USHERCTL addkey "$servername" -t `echo $1 | cut -f1 -d:`
+ shift
+ done
+ )
+ ;;
+ remote )
+ $USHERCTL add "$servername" -h "$hostname" -p "$pattern" remote "$1"
+ ;;
+ esac
+}
+
mkdir -p test-dir && cd test-dir
TESTDIR=$(pwd)
export TESTDIR
@@ -46,12 +97,18 @@ client() {
local what=$1
local database=$2
local uri="$3"
+ local key="$4"
uri="$(echo $uri | sed 's/HOST/127.0.0.1:8691/')"
[ -e $database.mtn ] || $mtn db init -d $database.mtn
+ key=${key:+"--key $key --keydir ./keys"}
# see usher.conf.head for address
- $mtn --root=. -d $database.mtn $what "$uri" &
+ $mtn --root=. -d $database.mtn $key $what "$uri" &
local mypid=$!
- CLIENTS="$CLIENTS $mypid"
+ if $XFAIL; then
+ XFAIL_CLIENTS="$XFAIL_CLIENTS $mypid"
+ else
+ CLIENTS="$CLIENTS $mypid"
+ fi
eval CLIENT_${mypid}='"$uri"'
}
@@ -72,8 +129,9 @@ multipull() {
multipull() {
count=$1
pattern="$2"
+ key="$3"
for ((i=0; i<$count; ++i)); do
- client pull multipull-$LINE-$i "$pattern"
+ client pull multipull-$LINE-$i "$pattern" "$key"
done
}
@@ -122,11 +180,21 @@ wait_for_clients() {
fi
done
CLIENTS=
+ for c in $XFAIL_CLIENTS; do
+ echo "Waiting for $c..."
+ if wait $c; then
+ echo "Client expected to fail but didn't: " "$(eval echo '$'CLIENT_$c)"
+ OK=false
+ fi
+ done
+ CLIENTS=
}
EXIT_STATUS=0
-for test_name in $(ls $SRCDIR/test/); do
+tests="$*"
+if [ -z "$tests" ]; then tests=$(ls $SRCDIR/test/); fi
+for test_name in $tests; do
if [ -d $SRCDIR/test/$test_name -a "$test_name" != "confdir" ]; then
echo "Running test $test_name..."
TEST_SRC=$SRCDIR/test/$test_name
@@ -136,40 +204,87 @@ for test_name in $(ls $SRCDIR/test/); do
cd $test_name
mkdir -p server-logs
- # populate databases used by the test
- if ! [ -d databases ]; then
- mkdir databases
- sed -n 's/#.*$//; /./ p' <$TEST_SRC/databases.txt | \
- while read line; do populate $line; done
- fi
- rm -f *.mtn
- cp databases/*.mtn ./
+ if [ -f $TEST_SRC/projects.txt ]; then
+ echo "($test_name is a test based on usherctl)"
+ if [ -d keys ]; then
+ rm -rf keys # We want to start fresh
+ fi
+ if [ -d usher ]; then
+ rm -rf usher # We want to start fresh
+ fi
+ if [ -d databases ]; then
+ rm -rf databases # We want to start fresh
+ fi
+ mkdir usher
+ mkdir usher/projects
+ USHER_HOME=$(pwd)/usher
+ (
+ echo "USHER_CONFDIR=\"$USHER_HOME\""
+ echo "USHER_PROJECTDIR=\"$USHER_HOME/projects\""
+ echo "USHER_PIDFILE=\"$USHER_HOME/usher.pid\""
+ echo "USHER_LOGDIR=\"$USHER_HOME/logs\""
+ echo "MTN=\"mtn\""
+ echo "USHER=\"$(cd ../..; pwd)/usher\""
+ ) > usherctl.conf
+ USHERCTL="../../usherctl -c usherctl.conf"
+ $USHERCTL init \
+ -a 127.0.0.1:55662 -l 127.0.0.1:8691 \
+ -A 127.0.0.1:23345 -u user -p pass
+ cat $TEST_SRC/keys.txt | \
+ sed -e '/^#/d' -e '/^[ ]*$/d' | \
+ while read line; do create_client_key $line; done
+
+ cat $TEST_SRC/projects.txt | \
+ sed -e '/^#/d' -e '/^[ ]*$/d' | \
+ while read line; do usherctl_mkproject $line; done
- # see if it works
- cp $SRCDIR/test/usher.conf.head usher.conf.full
- chmod +w usher.conf.full
- sed '/^local/ s,$, "--confdir" "'$TESTDIR/confdir'",' \
- < $TEST_SRC/usher.conf >> usher.conf.full
+ cat $TEST_SRC/databases.txt | \
+ sed -e '/^#/d' -e '/^[ ]*$/d' | \
+ while read line; do usherctl_populate $line; done
+ rm -f *.mtn
+ cp databases/*.mtn ./
- if [ -d $TEST_SRC/scripts ]
- then
- echo "Copying scripts..."
- [ -d scripts ] && rm -rf scripts
- cp -r $TEST_SRC/scripts/ scripts
- chmod -R +wx scripts
- find scripts
- fi
+ $USHERCTL start
+ sleep 1
+ USHER_STOP="echo 'Stopping usher (pid: `cat $USHER_HOME/usher.pid`)'; $USHERCTL stop"
+ elif [ -f $TEST_SRC/databases.txt ]; then
+ echo "($test_name is a test based on bare usher)"
+ # populate databases used by the test
+ if ! [ -d databases ]; then
+ mkdir databases
+ sed -n 's/#.*$//; /./ p' <$TEST_SRC/databases.txt | \
+ while read line; do populate $line; done
+ fi
+ rm -f *.mtn
+ cp databases/*.mtn ./
- ../../usher usher.conf.full &
- USHER=$!
- sleep 1
+ # see if it works
+ cp $SRCDIR/test/usher.conf.head usher.conf.full
+ chmod +w usher.conf.full
+ sed '/^local/ s,$, "--confdir" "'$TESTDIR/confdir'",' \
+ < $TEST_SRC/usher.conf >> usher.conf.full
+ if [ -d $TEST_SRC/scripts ]
+ then
+ echo "Copying scripts..."
+ [ -d scripts ] && rm -rf scripts
+ cp -r $TEST_SRC/scripts/ scripts
+ chmod -R +wx scripts
+ find scripts
+ fi
+
+ ../../usher usher.conf.full &
+ USHER_PID=$!
+ USHER_STOP="echo 'Killing usher (pid: $USHER_PID)'; kill $USHER_PID"
+ sleep 1
+ fi
OK=true
LINE=0
sed -n 's/#.*$//; /./ p' <$TEST_SRC/script.txt | {
SERVERS=
CLIENTS=
+ XFAIL_CLIENTS=
while read -r cmd rest; do
echo "Testing: $cmd $rest"
LINE=$(expr $LINE + 1)
@@ -177,7 +292,14 @@ for test_name in $(ls $SRCDIR/test/); do
stop)
break
;;
+ '!')
+ XFAIL=true
+ if ! eval "$rest"; then
+ OK=false
+ fi
+ ;;
*)
+ XFAIL=false
if ! eval $cmd "$rest"; then
OK=false
fi
@@ -194,8 +316,7 @@ for test_name in $(ls $SRCDIR/test/); do
echo "Killing any independent servers (pids: $SERVERS)..."
[ "$SERVERS" ] && kill $SERVERS
} | tee testlog.log
- echo "Killing usher (pid: $USHER)..."
- kill $USHER
+ eval "$USHER_STOP"
echo "Test finished."
fi
done
============================================================
--- /dev/null
+++ test/test2/databases.txt 26306a8d15153631a69ebbab8a33fcac411d3d99
@@ -0,0 +1,12 @@
+# populate projects prior to test
+# "project" projectname branch [count]
+project prjek net.prjek.fnord 100
+project prjek net.prjek 100
+
+project prjek-s net.prjek.separate 100
+
+# populate databases not controlled through usherctl
+# "database" database branch [count]
+database example org.example.test 100
+
+database user1 net.prjek.user 100
============================================================
--- /dev/null
+++ test/test2/keys.txt d5f519273d6c1f9edbd02fa654774d47ce6ec3cb
@@ -0,0 +1,5 @@
+# names for keys that need to get produced
address@hidden
address@hidden
address@hidden
address@hidden
============================================================
--- /dev/null
+++ test/test2/projects.txt d23a983e3ae7ea2a13e9e6159d114e574d995ab9
@@ -0,0 +1,7 @@
+# configure projects and servers prior to test
+
+# priv/pub servername hostname pattern keys
+# remote servername hostname pattern listenaddr
+priv prjek-s prjek-other net.prjek.separate rw:address@hidden ro:address@hidden
+pub prjek prjek net.prjek rw:address@hidden
+remote example example.org org.example 127.0.0.1:25436
============================================================
--- /dev/null
+++ test/test2/script.txt 90c8fbd0cb741592730841c1e3ba4c41ea4a1f47
@@ -0,0 +1,49 @@
+serve example 127.0.0.1:25436
+
+# The first multipull will fail, because that key isn't allowed to
+# read that branch
+! multipull 3 mtn://HOST/prjek-s?net.prjek.separate address@hidden
+multipull 3 mtn://HOST/prjek-s?net.prjek.separate address@hidden
+multipull 3 'mtn://HOST/prjek?net.prjek.{fnord,foobar}' address@hidden
+multipull 3 mtn://HOST/example?org.example
+
+sync user1 mtn://HOST/prjek?net.prjek'*' address@hidden
+
+# check_match <hostname> <pattern> <expected server>
+
+# by hostname
+check_match xyzzy.prjek.net '*' -
+check_match example.org '*' example
+
+# by pattern
+check_match - org.example.somebranch example
+check_match - com.example -
+
+# both, should prefer hostname
+check_match example.org net.prjek example
+check_match example.com com.example -
+
+# explicit server name
+check_match mtn://asdf/prjek - prjek
+check_match mtn://asdf/prjek-s - prjek-s
+check_match mtn://example.org - example
+check_match mtn://example.org/ - example
+check_match mtn://example.org/prjek - prjek
+check_match mtn://prjek.net/foobar net.prjek -
+
+# ...and with included sync pattern
+check_match mtn://asdf/prjek?foo - prjek
+check_match mtn://asdf/prjek-s?-bar - prjek-s
+check_match mtn://asdf/prjek?-s - prjek
+check_match mtn://example.org?prjek - example
+check_match mtn://example.org/prjek?prjek-s - prjek
+
+# add / remove server
+
+check_cmd REMOVE_SERVER prjek-s
+check_match mtn://HOST/prjek-s - -
+
+check_cmd ADD_SERVER someserver remote 127.0.0.1 25436
+sync user1 mtn://HOST/someserver?'*'
+check_cmd ADD_SERVER otherserver local "-d" "user1.mtn" "--confdir=../confdir"
+multipull 2 mtn://HOST/otherserver?'*'
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.contrib.usher: eab043a0c4ceb4bdfc8c8897dfc4b96b7e3c2df2,
code <=