# # # add_dir "test" # # add_dir "test/test1" # # add_file "test/monotonerc" # content [0a06aa28f6d90e8ce8c219a173618747cb04e759] # # add_file "test/populate-branch.sh" # content [823c038cc43b9b8f9abf210f293b95bf8f437a2d] # # add_file "test/run-tests.sh" # content [c316b811a0deb2e0f4964da970752fcfa89e9c7d] # # add_file "test/test1/databases.txt" # content [5a7861a32bfd7414c588723a402a5bd282f5bb2a] # # add_file "test/test1/script.txt" # content [d4354fe960c9683da2bd37f14c7ecc2e574649c6] # # add_file "test/test1/usher.conf" # content [e6a1128ffea536620f37b18dededc0c1487739de] # # add_file "test/usher.conf.head" # content [0e840f1cd9c3b9e0ac0937be7c10c955475f1506] # # patch "Makefile.am" # from [8c0d0c3b5133080e5f110608ceccbf562002eae0] # to [84470abfc7bf83839a2a88b50730bfd80fb16751] # # set "test/populate-branch.sh" # attr "mtn:execute" # value "true" # # set "test/run-tests.sh" # attr "mtn:execute" # value "true" # ============================================================ --- test/monotonerc 0a06aa28f6d90e8ce8c219a173618747cb04e759 +++ test/monotonerc 0a06aa28f6d90e8ce8c219a173618747cb04e759 @@ -0,0 +1,11 @@ +function get_passphrase(key) + return key +end + +function get_netsync_read_permitted(branch, ident) + return true +end + +function get_netsync_write_permitted(ident) + return true +end ============================================================ --- test/populate-branch.sh 823c038cc43b9b8f9abf210f293b95bf8f437a2d +++ test/populate-branch.sh 823c038cc43b9b8f9abf210f293b95bf8f437a2d @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +set -e + +database=$1 +branch=$2 +count=$3 + +if ! [ $database ]; then exit 1; fi +if ! [ $branch ]; then exit 1; fi +if ! [ $count ]; then count=100; fi + +mtn="mtn --confdir=$TESTDIR/confdir --quiet" + +if ! [ -d $TESTDIR/confdir/keys ] +then + $mtn au genkey address@hidden address@hidden +fi + +$mtn -d databases/$database setup -b $branch $branch + +pick_file() { + local files=$(ls | grep -v _MTN | wc -l) + local line=$(expr 1 + \( $RANDOM % $files \)) + ls | grep -v _MTN | head -n $line | tail -n1 +} + +commit() { + $mtn ci -m "" +} + +do_add() { + local file=$(mktemp file.XXXXXX) + dd if=/dev/urandom bs=1 count=4096 >$file 2>/dev/null + $mtn add $file +} + +do_edit() { + local file=$(pick_file) + dd if=/dev/urandom bs=1 count=96 seek=$(expr $RANDOM % 4000 || true) >$file 2>/dev/null +} + +do_rename() { + local file1=$(pick_file) + local file2=$(mktemp -u file.XXXXXX) + $mtn rename $file1 $file2 +} + +do_something() { + local what=$(expr $RANDOM % 100 || true) + if [ $what -lt 10 ]; then + do_add + elif [ $what -lt 40 ]; then + do_rename + else + do_edit + fi +} + +cd $branch + +do_add +commit + +for ((i=1; i<$count; ++i)); do + do_something + commit + printf "$i\r" $i +done + +cd .. + +rm -r $branch ============================================================ --- test/run-tests.sh c316b811a0deb2e0f4964da970752fcfa89e9c7d +++ test/run-tests.sh c316b811a0deb2e0f4964da970752fcfa89e9c7d @@ -0,0 +1,135 @@ +#!/usr/bin/env bash + +set -e + +SRCDIR=$(cd $srcdir && pwd) + +populate() { + echo "$@" >&2 + local database=$1 + local branch=$2 + local count=$3 + if ! [ -e databases/$database.mtn ]; then + mtn -d databases/$database.mtn db init + fi + if [ ! $count ] || [ $count -gt 0 ]; then + $SRCDIR/test/populate-branch.sh $database.mtn $branch $count + fi +} + +mkdir -p test && cd test +TESTDIR=$(pwd) +export TESTDIR +rm -f $TESTDIR/status + +mkdir -p confdir +cp $SRCDIR/test/monotonerc confdir/ + +mtn="mtn --confdir=$TESTDIR/confdir --ticker=none" + +serve() { + $mtn -d $1.mtn serve --bind $2 & + SERVERS="$SERVERS $!" +} + +client() { + local what=$1 + local database=$2 + local pattern=$3 + [ -e $database.mtn ] || $mtn db init -d $database.mtn + # see usher.conf.head for address + $mtn --root=. -d $database.mtn $what 127.0.3.1:8691 $pattern & + CLIENTS="$CLIENTS $!" +} + +EXIT_STATUS=0 + +for test_name in $(ls $SRCDIR/test/); do + if [ -d $SRCDIR/test/$test_name ]; then + echo "Running test $test_name..." + TEST_SRC=$SRCDIR/test/$test_name + cd $TESTDIR + + mkdir -p $test_name + 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 ./ + + # see if it works + cp $SRCDIR/test/usher.conf.head usher.conf + sed '/^local/ s,$, "--confdir" "'$TESTDIR/confdir'",' \ + < $TEST_SRC/usher.conf >> usher.conf + + ../../usher usher.conf & + USHER=$! + sleep 1 + LINE=0 + sed -n 's/#.*$//; /./ p' <$TEST_SRC/script.txt | { + SERVERS= + CLIENTS= + while read cmd a1 a2 a3; do + echo "Testing: $cmd $a1 $a2 $a3" + LINE=$(expr $LINE + 1) + case $cmd in + serve) + database=$a1 + address=$a2 + serve $database $address + ;; + multipull) + count=$a1 + pattern=$a2 + for ((i=0; i<$count; ++i)); do + client pull multipull-$LINE-$i $pattern + done + ;; + sync) + database=$a1 + pattern=$a2 + client sync $database $pattern + ;; + check_match) + hostname=$a1 + pattern=$a2 + server=$a3 + echo "FIXME: check_match doesn't do anything" + ;; + stop) + break + ;; + esac + #sleep 1 + done + echo "Reached end of script, waiting for clients to die..." + OK=true + for c in $CLIENTS; do + echo "Waiting for $c..." + if ! wait $c; then + echo "Client died horribly." + OK=false + fi + done + if $OK; then + echo "PASS $test_name" >>$TESTDIR/status + else + echo "FAIL $test_name" >>$TESTDIR/status + fi + echo "Killing any independent servers (pids: $SERVERS)..." + [ "$SERVERS" ] && kill $SERVERS + } | tee testlog.log + echo "Killing usher (pid: $USHER)..." + kill $USHER + echo "Test finished." + fi +done + +cat $TESTDIR/status +! grep -q FAIL $TESTDIR/status ============================================================ --- test/test1/databases.txt 5a7861a32bfd7414c588723a402a5bd282f5bb2a +++ test/test1/databases.txt 5a7861a32bfd7414c588723a402a5bd282f5bb2a @@ -0,0 +1,10 @@ +# database branch [count] +# populate databases prior to test +prjek net.prjek.fnord 100 +prjek net.prjek 100 + +prjek-separate net.prjek.separate 100 + +example org.example.test 100 + +user1 net.prjek.user 100 ============================================================ --- test/test1/script.txt d4354fe960c9683da2bd37f14c7ecc2e574649c6 +++ test/test1/script.txt d4354fe960c9683da2bd37f14c7ecc2e574649c6 @@ -0,0 +1,30 @@ +serve example 127.1.1.87:25436 + +multipull 3 net.prjek.separate +multipull 3 net.prjek.{fnord,foobar} +multipull 3 org.example + +sync user1 net.prjek* + +# check_match + +# by hostname +check_match prjek.net * prjek +check_match prjek-other.prjek.net * prjek-s +check_match prjek-fnord.prjek.net * prjek +check_match xyzzy.prjek.net * - +check_match example.org * example + +# by pattern +check_match - net.prjek.foo prjek +check_match - net.prjek prjek +check_match - net.prjek.separate prjek-s +check_match - org.example.somebranch example +check_match - com.example - + +# both, should prefer hostname +check_match prjek.net prjek.net.separate prjek +check_match example.org net.prjek example +check_match prjek-other net.prjek prjek-s +check_match prjek.net org.example.foobar prjek +check_match example.com com.example - ============================================================ --- test/test1/usher.conf e6a1128ffea536620f37b18dededc0c1487739de +++ test/test1/usher.conf e6a1128ffea536620f37b18dededc0c1487739de @@ -0,0 +1,15 @@ +server "prjek-s" +host "prjek-other" +pattern "net.prjek.separate" +local "-d" "prjek-separate.mtn" + +server "prjek" +host "prjek" +pattern "net.prjek" +local "-d" "prjek.mtn" + +server "example" +host "example.org" +pattern "org.example" +remote "127.1.1.87:25436" + ============================================================ --- test/usher.conf.head 0e840f1cd9c3b9e0ac0937be7c10c955475f1506 +++ test/usher.conf.head 0e840f1cd9c3b9e0ac0937be7c10c955475f1506 @@ -0,0 +1,6 @@ +userpass "user" "pass" +listenaddr "127.0.3.1:8691" +automateaddr "127.0.1.1:55662" +adminaddr "127.0.4.2:12345" +monotone "mtn" +logdir "server-logs" ============================================================ --- Makefile.am 8c0d0c3b5133080e5f110608ceccbf562002eae0 +++ Makefile.am 84470abfc7bf83839a2a88b50730bfd80fb16751 @@ -17,6 +17,8 @@ usher_CPPFLAGS = -Wall -pedantic -Wextra usher_CPPFLAGS = -Wall -pedantic -Wextra +TESTS=test/run-tests.sh + EXTRA_DIST = ChangeLog.txt ChangeLog.txt: