lsyncd/tests/randomrsync.lua

61 lines
1.5 KiB
Lua
Raw Normal View History

2010-11-18 16:33:48 +00:00
#!/usr/bin/lua
-- a heavy duty test.
-- makes thousends of random changes to the source tree
-- checks every X changes if lsyncd managed to keep target tree in sync.
require("posix")
dofile("tests/testlib.lua")
-- always makes the same "random", so failures can be debugged.
math.randomseed(1)
2010-11-18 16:59:50 +00:00
local tdir = mktempd().."/"
2010-11-18 16:33:48 +00:00
cwriteln("using ", tdir, " as test root")
local srcdir = tdir.."src/"
local trgdir = tdir.."trg/"
posix.mkdir(srcdir)
posix.mkdir(trgdir)
2010-11-18 16:59:50 +00:00
local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir)
2010-11-18 16:33:48 +00:00
2010-11-18 16:59:50 +00:00
cwriteln("waiting for Lsyncd to startup")
2010-11-18 16:33:48 +00:00
posix.sleep(1)
-- all dirs created, indexed by integer and path
adiri = {""}
adirp = {[""]=true}
2010-11-18 16:59:50 +00:00
cwriteln("making random data")
2010-11-18 16:33:48 +00:00
for ai=1,100 do
-- throw a die what to do
local acn = math.random(1)
-- 1 .. creates a directory
if acn == 1 then
-- chooses a random directory to create it into
2010-11-18 16:59:50 +00:00
local ri = math.random(#adiri)
local rp = adiri[ri]
2010-11-18 16:33:48 +00:00
local np = rp..string.char(96 + math.random(26)).."/"
if not adirp[np] then
-- does not yet exist.
2010-11-18 16:59:50 +00:00
cwriteln("mkdir "..srcdir..np)
posix.mkdir(srcdir..np)
2010-11-18 16:33:48 +00:00
table.insert(adiri, np)
adirp[np]=true
end
end
end
2010-11-18 16:59:50 +00:00
cwriteln("waiting for Lsyncd to finish its jobs.")
posix.sleep(20)
2010-11-18 16:33:48 +00:00
2010-11-18 16:59:50 +00:00
cwriteln("killing the Lsyncd daemon")
posix.kill(pid)
local _, exitmsg, exitcode = posix.wait(lpid)
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode)
2010-11-18 16:33:48 +00:00
2010-11-18 16:59:50 +00:00
exitcode = os.execute("diff -r "..srcdir.." "..trgdir)
cwriteln("Exitcode of diff = ", exitcode)
os.exit(exitcode)
2010-11-18 16:33:48 +00:00