diff --git a/Makefile.am b/Makefile.am index 0e2ef3a..d1fbf57 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,7 @@ bin_PROGRAMS = lsyncd lsyncd_SOURCES = lsyncd.c TESTS = tests/help.sh \ tests/directorymv.sh \ + tests/directorycpr.sh \ tests/pidfile.sh \ tests/version.sh \ tests/wrong-logfile.sh \ diff --git a/tests/directorycpr.sh b/tests/directorycpr.sh new file mode 100755 index 0000000..a14267f --- /dev/null +++ b/tests/directorycpr.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# test the case of directory being cp -r'ed and touched. lsyncd 1.0 doesn't handle this case well. + +set -e + +WORKSOURCE=$(mktemp -d) +WORKTARGET=$(mktemp -d) +PIDFILE=$(mktemp) +LOGFILE=$(mktemp) + +# populate the filesystem. +mkdir -p "${WORKSOURCE}"/a/a +echo 'test' > "${WORKSOURCE}"/a/a/file + +./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}" + +# try to wait until lsyncd starts and rsyncs initial file, hope 1s is enough. +sleep 2s + +# cp -r the directory, this sometimes succeeds, sometimes fails. +for A in 1 2 3 4 5 6 7 8 9 10; do + cp -r "${WORKSOURCE}"/a "${WORKSOURCE}"/b${A} + echo 'test2' > "${WORKSOURCE}"/b${A}/a/another +done + +# mkdir path while lsyncd is running +mkdir -p "${WORKSOURCE}"/c/a +echo 'test3' > "${WORKSOURCE}"/c/a/file + +# cp the dir while lsyncd is running. +# it's a race condition, do it 10 times. +for A in 1 2 3 4 5 6 7 8 9 10; do + cp -r "${WORKSOURCE}"/c "${WORKSOURCE}"/d${A} + echo 'test2' > "${WORKSOURCE}"/d${A}/a/another +done + +# try to wait until lsyncd does the job. +sleep 2s + +LSYNCPID=$(cat "${PIDFILE}") +if ! kill "${LSYNCPID}"; then + cat "${LOGFILE}" + diff -urN "${WORKSOURCE}" "${WORKTARGET}" || true + echo "kill failed" + exit 1 +fi +sleep 1s + + +echo "log file contents" +cat "${LOGFILE}" +#this should be grep. + +diff -urN "${WORKSOURCE}" "${WORKTARGET}" + +rm "${PIDFILE}" +rm "${LOGFILE}" +rm -rf "${WORKTARGET}" +rm -rf "${WORKSOURCE}"