mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-10-31 18:52:29 +00:00
less bash scripts, more lua scripts for testing
This commit is contained in:
parent
e22691e111
commit
e0c9746e6e
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
54
tests/l4rsyncdata.lua
Executable file
54
tests/l4rsyncdata.lua
Executable file
@ -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
|
@ -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.
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user