# HG changeset patch # User Olaf Wintermann # Date 1566682456 -7200 # Node ID 93bbeb00385c35706783a0ac4b891f17b2879f02 # Parent 046b869a1c49ff30b93ac35bb0e4754102fe0ab1 add pull conflict detection tests diff -r 046b869a1c49 -r 93bbeb00385c test/bin-test/test-dav-sync-conflict.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bin-test/test-dav-sync-conflict.sh Sat Aug 24 23:34:16 2019 +0200 @@ -0,0 +1,355 @@ +#!/bin/sh +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2019 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# +# Test dav-sync pull conflict detection +# and related commands +# + +if [ -z "$DAV_BIN" ]; +then + echo "DAV_BIN variable not set" + exit 1 +fi +if [ -z "$DAV_SYNC_BIN" ]; +then + echo "DAV_BIN variable not set" + exit 1 +fi + +# checks if tmp-sync/out.txt contains a specific text +# arg1: pattern +# arg2: errormsg +check_tmpout() +{ + TEST=`cat tmp-sync/out.txt | grep "$1"` + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} + +# do dav-sync push and check return value +# arg1: dir +# arg2: errormsg +dav_sync_push() +{ + $DAV_SYNC_BIN push $1 > tmp-sync/out.txt + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} +# do dav-sync pull and check return value +# arg1: dir +# arg2: errormsg +dav_sync_pull() +{ + $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} + +rm -f .dav/dav-sync-tests-test1a-db.xml +rm -f .dav/dav-sync-tests-test1b-db.xml + +$DAV_BIN rm dav-test-repo/sync/test1 2> /dev/null +$DAV_BIN rm dav-test-repo/sync/test2 2> /dev/null + +$DAV_BIN mkcol dav-test-repo/sync/test1 2> /dev/null +$DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null + +# prepare +cp synctest/file1 tmp-sync/test1a +cp synctest/file2 tmp-sync/test1a +dav_sync_push test1a "prepare: push failed" +dav_sync_pull test1b "prepare: pull failed" +sleep 3 + +# ---------------------------------------------------------------------------- +# 1. test: pull, local file also modified +# expected result: 1 conflict + +echo "conflict1-test1" >> tmp-sync/test1a/file1 +dav_sync_push test1a "prepare: push failed" +check_tmpout "1 file pushed" "test 1: wrong push counter" + +TEST1B_COUNT1=`ls tmp-sync/test1b/ | wc -l` + +echo "conflict1-test1-conflict" >> tmp-sync/test1b/file1 +dav_sync_pull test1b "prepare: pull failed" +check_tmpout "1 file pulled" "test 1: wrong pull counter" +check_tmpout "1 conflict" "test 1: wrong conflict counter" +check_tmpout "0 errors" "test 1: wrong error counter" + +TEST1B_COUNT2=`ls tmp-sync/test1b/ | wc -l` +# check if the conflict file was moved +if [ $TEST1B_COUNT1 = $TEST1B_COUNT2 ]; then + echo "test 1: conflict file not renamed" + exit 2 +fi + +# warning: never check if the moved conflict file has a specific +# name like "orig.0.file1" + +# ---------------------------------------------------------------------------- +# 2. test: check list-conflicts command +# expected result: "/file1" output + +$DAV_SYNC_BIN list-conflicts test1b > tmp-sync/out.txt +if [ $? -ne 0 ]; then + echo "test 2: list-conflicts failed" + exit 2 +fi +TEST=`cat tmp-sync/out.txt | grep "/file1"` +if [ $? -ne 0 ]; +then + echo "test 2: wrong list-conflicts output" + exit 2 +fi + +# ---------------------------------------------------------------------------- +# 3. test: check delete-conflicts command +# expected result: conflict file ("/orig.0.file1") deleted + +# don't check if the conflict file has this specific name + +$DAV_SYNC_BIN delete-conflicts test1b > tmp-sync/out.txt +if [ $? -ne 0 ]; then + echo "test 3: delete-conflicts failed" + exit 2 +fi +TEST=`cat tmp-sync/out.txt | grep "1 conflict file deleted"` +if [ $? -ne 0 ]; +then + echo "test 3: wrong delete-conflicts output" + exit 2 +fi + +TEST1B_COUNT3=`ls tmp-sync/test1b/ | wc -l` + +if [ $TEST1B_COUNT1 != $TEST1B_COUNT3 ]; then + echo "test 3: file not removed" + exit 2 +fi + +# ---------------------------------------------------------------------------- +# 4. test: pull after deleted conflicts +# expected result: 0 files pulled, 0 conflicts + +dav_sync_pull test1b "test 4: pull failed" +check_tmpout "0 files pulled" "test 4: wrong pull counter" +check_tmpout "0 conflicts" "test 4: wrong conflict counter" +check_tmpout "0 errors" "test 4: wrong error counter" + +# ---------------------------------------------------------------------------- +# 5. test: pull, local file also modified, delete-conflicts +# this test prepares test 6, to test 'push' after 'delete-conflicts' +# expected result: 0 files pulled, 0 conflicts + +sleep 3 # make sure mtime changes + +echo "conflict1-test5" >> tmp-sync/test1a/file1 +dav_sync_push test1a "prepare: push failed" +check_tmpout "1 file pushed" "test 1: wrong push counter" + +echo "conflict1-test5-conflict" >> tmp-sync/test1b/file1 +dav_sync_pull test1b "prepare: pull failed" +check_tmpout "1 file pulled" "test 1: wrong pull counter" +check_tmpout "1 conflict" "test 1: wrong conflict counter" +check_tmpout "0 errors" "test 1: wrong error counter" + +$DAV_SYNC_BIN delete-conflicts test1b > tmp-sync/out.txt +if [ $? -ne 0 ]; then + echo "test 3: delete-conflicts failed" + exit 2 +fi +TEST=`cat tmp-sync/out.txt | grep "1 conflict file deleted"` +if [ $? -ne 0 ]; +then + echo "test 3: wrong delete-conflicts output" + exit 2 +fi + + +# ---------------------------------------------------------------------------- +# 6. test: push after deleted conflicts +# expected result: 0 files pushed, 0 conflicts + +dav_sync_push test1b "test 6: push failed" +check_tmpout "0 files pushed" "test 6: wrong push counter" +check_tmpout "0 conflicts" "test 6: wrong conflict counter" +check_tmpout "0 errors" "test 6: wrong error counter" + + +# ---------------------------------------------------------------------------- +# 7. test: resolve-conflicts after pull, followed by push +# expected result: pull with 1 conflict, resolve-conflicts removes conflicts +# from db (list-conflicts doesn't show conflicts after that) + +sleep 3 # make sure mtime changes + +echo "conflict1-test7" >> tmp-sync/test1a/file1 +dav_sync_push test1a "prepare: push failed" +check_tmpout "1 file pushed" "test 7: wrong push counter" + +echo "conflict1-test7-conflict" >> tmp-sync/test1b/file1 +dav_sync_pull test1b "prepare: pull failed" +check_tmpout "1 file pulled" "test 7: wrong pull counter" +check_tmpout "1 conflict" "test 7: wrong conflict counter" +check_tmpout "0 errors" "test 7: wrong error counter" + +TEST1B_COUNT_T7_1=`ls tmp-sync/test1b/ | wc -l` + +$DAV_SYNC_BIN resolve-conflicts test1b > tmp-sync/out.txt +if [ $? -ne 0 ]; then + echo "test 7: resolve-conflicts failed" + exit 2 +fi +TEST=`cat tmp-sync/out.txt | grep "1 conflict resolved"` +if [ $? -ne 0 ]; +then + echo "test 7: wrong resolve-conflicts output" + exit 2 +fi + +TEST1B_COUNT_T7_2=`ls tmp-sync/test1b/ | wc -l` + +if [ $TEST1B_COUNT_T7_1 != $TEST1B_COUNT_T7_2 ]; then + echo "test 7: number of files has changed" + exit 2 +fi + +TEST7=`dav-sync list-conflicts test1b | wc -l` +if [ $TEST7 != "0" ]; then + echo "test 7: list-conflicts must not show conflicts" + return 2 +fi + +# pull again, should do nothing + +dav_sync_pull test1b "test 7: pull(2) failed" +check_tmpout "0 files pulled" "test 7: wrong pull counter (2)" +check_tmpout "0 conflicts" "test 7: wrong conflict counter (2)" +check_tmpout "0 errors" "test 7: wrong error counter (2)" + +# ---------------------------------------------------------------------------- +# 8. test: resolve-conflicts after pull, followed by push +# expected result: pull with 1 conflict, resolve-conflicts removes conflicts +# from db (list-conflicts doesn't show conflicts after that) + +# test mostly the same as test 7 + +sleep 3 # make sure mtime changes + +echo "conflict1-test8" >> tmp-sync/test1a/file1 +dav_sync_push test1a "prepare: push failed" +check_tmpout "1 file pushed" "test 8: wrong push counter" + +echo "conflict1-test8-conflict" >> tmp-sync/test1b/file1 +dav_sync_pull test1b "prepare: pull failed" +check_tmpout "1 file pulled" "test 8: wrong pull counter" +check_tmpout "1 conflict" "test 8: wrong conflict counter" +check_tmpout "0 errors" "test 8: wrong error counter" + +TEST1B_COUNT_T7_1=`ls tmp-sync/test1b/ | wc -l` + +$DAV_SYNC_BIN resolve-conflicts test1b > tmp-sync/out.txt +if [ $? -ne 0 ]; then + echo "test 8: resolve-conflicts failed" + exit 2 +fi +TEST=`cat tmp-sync/out.txt | grep "1 conflict resolved"` +if [ $? -ne 0 ]; +then + echo "test 8: wrong resolve-conflicts output" + exit 2 +fi + +TEST1B_COUNT_T7_2=`ls tmp-sync/test1b/ | wc -l` + +if [ $TEST1B_COUNT_T7_1 != $TEST1B_COUNT_T7_2 ]; then + echo "test 8: number of files has changed" + exit 2 +fi + +TEST7=`dav-sync list-conflicts test1b | wc -l` +if [ $TEST7 != "0" ]; then + echo "test 8: list-conflicts must not show conflicts" + return 2 +fi + +# push, 2 resolved conflict files (test 7 and test 8 'orig' file) + +dav_sync_push test1b "test 8: push failed" +check_tmpout "2 files pushed" "test 8: wrong push counter" +check_tmpout "0 conflicts" "test 8: wrong conflicts counter" +check_tmpout "0 errors" "test 8: wrong error counter" + +# push again, shoud do nothing +dav_sync_push test1b "test 8: push(2) failed" +check_tmpout "0 files pushed" "test 8: wrong push counter (2)" +check_tmpout "0 conflicts" "test 8: wrong conflicts counter (2)" +check_tmpout "0 errors" "test 8: wrong error counter (2)" + + +# ---------------------------------------------------------------------------- +# 9. test: test1a deleted file, test1b modified file +# expected result: conflict + +sleep 3 # make sure mtime changes + +rm -f tmp-sync/test1a/file1 + +dav_sync_push test1a "test 9: push failed" +check_tmpout "1 file deleted" "test 9: wrong delete counter" +check_tmpout "0 conflicts" "test 9: wrong conflict counter" + +echo "conflict1-test9-conflict" >> tmp-sync/test1b/file1 + +dav_sync_pull test1b "test 9: pull failed" +# don't check conflict counter +TEST=`cat tmp-sync/out.txt | grep "1 file deleted"` +if [ $? -eq 0 ]; +then + echo "test 9: file1 deleted" + exit 2 +fi + +cat tmp-sync/test1b/file1 > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "test 9: file1 deleted (2)" + exit 2 +fi + diff -r 046b869a1c49 -r 93bbeb00385c test/bin-test/test-dav-sync.sh --- a/test/bin-test/test-dav-sync.sh Mon Aug 19 19:19:08 2019 +0200 +++ b/test/bin-test/test-dav-sync.sh Sat Aug 24 23:34:16 2019 +0200 @@ -92,6 +92,7 @@ # do_test "dav-sync push (1)" test-dav-sync-push1.sh do_test "dav-sync pull (1)" test-dav-sync-pull1.sh +do_test "dav-sync conflict (1)" test-dav-sync-conflict.sh # cleanup $DAV_BIN rm dav-test-repo/sync/test1 > /dev/null 2>&1