From e0c9746e6e8ca7b7f52670f2ef587f8c55867859 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Tue, 30 Nov 2010 09:42:44 +0000 Subject: [PATCH] less bash scripts, more lua scripts for testing --- tests/churn-rsync.lua | 9 +----- tests/churn-rsyncssh.lua | 9 +----- tests/l4-rsync-data.sh | 70 ---------------------------------------- tests/l4rsyncdata.lua | 54 +++++++++++++++++++++++++++++++ tests/testlib.lua | 35 ++++++++++++++++++++ 5 files changed, 91 insertions(+), 86 deletions(-) delete mode 100755 tests/l4-rsync-data.sh create mode 100755 tests/l4rsyncdata.lua diff --git a/tests/churn-rsync.lua b/tests/churn-rsync.lua index 2827871..f55db42 100755 --- a/tests/churn-rsync.lua +++ b/tests/churn-rsync.lua @@ -5,14 +5,7 @@ require("posix") dofile("tests/testlib.lua") -local tdir = mktempd().."/" -cwriteln("using ", tdir, " as test root") - -local srcdir = tdir.."src/" -local trgdir = tdir.."trg/" - -posix.mkdir(srcdir) -posix.mkdir(trgdir) +local tdir, srcdir, trdir = mktemps() -- makes some startup data churn(srcdir, 10) diff --git a/tests/churn-rsyncssh.lua b/tests/churn-rsyncssh.lua index ba9beb9..d95d444 100755 --- a/tests/churn-rsyncssh.lua +++ b/tests/churn-rsyncssh.lua @@ -5,14 +5,7 @@ require("posix") dofile("tests/testlib.lua") -local tdir = mktempd().."/" -cwriteln("using ", tdir, " as test root") - -local srcdir = tdir.."src/" -local trgdir = tdir.."trg/" - -posix.mkdir(srcdir) -posix.mkdir(trgdir) +local tdir, srcdir, trdir = mktemps() -- makes some startup data churn(srcdir, 10) diff --git a/tests/l4-rsync-data.sh b/tests/l4-rsync-data.sh deleted file mode 100755 index d8f512f..0000000 --- a/tests/l4-rsync-data.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash - -RANGE=1 -LOG="-log all" - -set -e -C1="\E[47;34m" -C0="\033[0m" - -echo -e "$C1****************************************************************$C0" -echo -e "$C1 Testing layer 4 default rsync with simulated data activity $C0" -echo -e "$C1****************************************************************$C0" -echo - -# root tmp dir -R=$(mktemp -d) -# source dir -S=$R/source -# target dir -T=$R/target -# logfile -L=$R/log -# pidfile -P=$R/pid - -echo -e "$C1* using root dir for test $R$C0" -echo -e "$C1* populating the source$C0" -echo -e "$C1* ceating d[x]/e/f1 $C0" -mkdir -p "$S"/d/e -echo 'test' > "$S"/d/e/f1 -echo -e "$C1* starting lsyncd$C0" -# lets bash detatch Lsyncd instead of itself; lets it log stdout as well. -echo ./lsyncd $LOG -logfile "$L" -pidfile "$P" -nodaemon -rsync "$S" "$T" -./lsyncd $LOG -logfile "$L" -pidfile "$P" -nodaemon -rsync "$S" "$T" & -echo -e "$C1* waiting for lsyncd to start$C0" -sleep 4s - -# cp -r the directory -echo -e "$C1* making some data$C0" -echo -e "$C1* ceating d[x]/e/f2 $C0" -for i in $RANGE; do - cp -r "$S"/d "$S"/d${i} -# echo 'test2' > "$S"/d${i}/e/f2 -done - -#mkdir -p "$S"/m/n -#echo 'test3' > "$S"/m/n/file -#for i in $RANGE; do -# cp -r "$S"/m "$S"/m$i -# echo 'test4' > "$S"/m${i}/n/another -#done - -echo -e "$C1* waiting for Lsyncd to do its job.$C0" -sleep 20s - -echo -e "$C1* killing Lsyncd$C0" -PID=$(cat "$P") -if ! kill "$PID"; then - cat "$L" - diff -urN "$S" "$T" || true - echo "kill failed" - exit 1 -fi -sleep 1s - -echo -e "$C1* differences$C0" -diff -urN "$S" "$T" - -#rm -rf "$R" - diff --git a/tests/l4rsyncdata.lua b/tests/l4rsyncdata.lua new file mode 100755 index 0000000..9f9404f --- /dev/null +++ b/tests/l4rsyncdata.lua @@ -0,0 +1,54 @@ +#!/usr/bin/lua +require("posix") +dofile("tests/testlib.lua") + +cwriteln("****************************************************************") +cwriteln(" Testing layer 4 default rsync with simulated data activity ") +cwriteln("****************************************************************") + +local tdir, srcdir, trgdir = mktemps() +local logfile = tdir .. "log" +local range = 5 +local log = {"-log", "all"} + +posix.mkdir(srcdir .. "d") +posix.mkdir(srcdir .. "d/e") +if not writefile(srcdir .. "d/e/f1", 'test') then + os.exit(1) +end +cwriteln("starting Lsyncd") + +logs = {} +local pid = spawn("./lsyncd", "-logfile", logfile, "-nodaemon", "-delay", "5", + "-rsync", srcdir, trgdir, unpack(logs)) +cwriteln("waiting for lsyncd to start") +posix.sleep(2) + +cwriteln("* making some data") +cwriteln("* creating d[x]/e/f2") +for i = 1, range do + cwriteln("[cp -r "..srcdir.."d "..srcdir.."d"..i.."]") + os.execute("cp -r "..srcdir.."d "..srcdir.."d"..i) +end + +-- mkdir -p "$S"/m/n +-- echo 'test3' > "$S"/m/n/file +-- for i in $RANGE; do +-- cp -r "$S"/m "$S"/m$i +-- echo 'test4' > "$S"/m${i}/n/another +-- done + +cwriteln("* waiting for Lsyncd to do its job.") +posix.sleep(10) + +cwriteln("* killing Lsyncd") + +posix.kill(pid) +local _, exitmsg, lexitcode = posix.wait(lpid) +cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", lexitcode) +posix.sleep(1) + +cwriteln("* differences:") +os.execute("diff -urN "..srcdir.." "..trgdir) + +-- TODO remove temp diff --git a/tests/testlib.lua b/tests/testlib.lua index 4a88010..b5e37c6 100644 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -34,6 +34,41 @@ function mktempd() return s end +----- +-- creates a tmp directory with the +-- typical lsyncd test architecture +-- +-- @returns path of tmpdir +-- path of srcdir +-- path of trgdir +-- + +function mktemps() + local tdir = mktempd().."/" + cwriteln("using ", tdir, " as test root") + local srcdir = tdir.."src/" + local trgdir = tdir.."trg/" + posix.mkdir(srcdir) + posix.mkdir(trgdir) + return tdir, srcdir, trgdir +end + +---- +-- Writes a file with 'text' in it. +-- and adds a newline. +-- +function writefile(filename, text) + local f = io.open(filename, "w") + if not f then + cwriteln("Cannot open '"..filename.."' for writing.") + return false + end + f:write(text) + f:write('\n') + f:close() + return true +end + ----- -- spawns a subprocess. --