mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-09 01:44:16 +00:00
working on random test
This commit is contained in:
parent
3ec485505f
commit
0c7bc18595
@ -1,64 +0,0 @@
|
|||||||
#!/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")
|
|
||||||
|
|
||||||
-- always makes the same "random", so failures can be debugged.
|
|
||||||
math.randomseed(1)
|
|
||||||
|
|
||||||
-- escape codes to colorize output on terminal
|
|
||||||
local c1="\027[47;34m"
|
|
||||||
local c0="\027[0m"
|
|
||||||
|
|
||||||
---
|
|
||||||
-- writes colorized
|
|
||||||
--
|
|
||||||
function cwriteln(...)
|
|
||||||
io.write(c1)
|
|
||||||
io.write(...)
|
|
||||||
io.write(c0, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
cwriteln("******************************************************************")
|
|
||||||
cwriteln("* heavy duty tests duing randoms *")
|
|
||||||
cwriteln("******************************************************************")
|
|
||||||
|
|
||||||
local lpid = posix.fork()
|
|
||||||
if lpid < 0 then
|
|
||||||
cwriteln("ERROR: failed fork!")
|
|
||||||
os.exit(-1);
|
|
||||||
end
|
|
||||||
if lpid == 0 then
|
|
||||||
posix.exec("./lsyncd", "-nodaemon", "-log", "all", "-rsync", "src", "trg")
|
|
||||||
-- should not return
|
|
||||||
cwriteln("ERROR: failed to spawn lysncd!")
|
|
||||||
os.exit(-1);
|
|
||||||
end
|
|
||||||
|
|
||||||
-- cleans the targets
|
|
||||||
os.execute("rm -rf src/*")
|
|
||||||
os.execute("rm -rf trg/*")
|
|
||||||
posix.sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
while true do
|
|
||||||
-- throw a die what to do
|
|
||||||
local acn = math.random(2)
|
|
||||||
if acn == 1 then
|
|
||||||
-- creates a directory
|
|
||||||
print(string.char(96))
|
|
||||||
end
|
|
||||||
if acn == 2 then
|
|
||||||
-- creates a files
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
-- kills the lsyncd daemon
|
|
||||||
posix.kill(lpid)
|
|
||||||
local _, exitmsg, exitcode = posix.wait(lpid)
|
|
||||||
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode)
|
|
||||||
os.exit(lexitcode)
|
|
||||||
|
|
54
tests/randomrsync.lua
Executable file
54
tests/randomrsync.lua
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/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)
|
||||||
|
|
||||||
|
local tdir = mktempd()
|
||||||
|
cwriteln("using ", tdir, " as test root")
|
||||||
|
|
||||||
|
local srcdir = tdir.."src/"
|
||||||
|
local trgdir = tdir.."trg/"
|
||||||
|
|
||||||
|
posix.mkdir(srcdir)
|
||||||
|
posix.mkdir(trgdir)
|
||||||
|
spawn("./lsyncd","-nodaemon","-log","all","-rsync",srcdir,trgdir)
|
||||||
|
|
||||||
|
-- lets Lsyncd startup
|
||||||
|
posix.sleep(1)
|
||||||
|
|
||||||
|
-- all dirs created, indexed by integer and path
|
||||||
|
adiri = {""}
|
||||||
|
adirp = {[""]=true}
|
||||||
|
|
||||||
|
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
|
||||||
|
local ri = math.random(adirs.size())
|
||||||
|
local rp = adiri[dn]
|
||||||
|
local np = rp..string.char(96 + math.random(26)).."/"
|
||||||
|
if not adirp[np] then
|
||||||
|
-- does not yet exist.
|
||||||
|
posix.mkdir(np)
|
||||||
|
table.insert(adiri, np)
|
||||||
|
adirp[np]=true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- kills the lsyncd daemon
|
||||||
|
-- posix.kill(lpid)
|
||||||
|
-- local _, exitmsg, exitcode = posix.wait(lpid)
|
||||||
|
-- cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode)
|
||||||
|
-- os.exit(lexitcode)
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
-- common testing environment
|
-- common testing environment
|
||||||
|
|
||||||
require("posix")
|
require("posix")
|
||||||
|
|
||||||
|
|
||||||
-- escape codes to colorize output on terminal
|
-- escape codes to colorize output on terminal
|
||||||
local c1="\027[47;34m"
|
local c1="\027[47;34m"
|
||||||
local c0="\027[0m"
|
local c0="\027[0m"
|
||||||
@ -28,6 +28,8 @@ end
|
|||||||
-----
|
-----
|
||||||
-- spawns a subprocess.
|
-- spawns a subprocess.
|
||||||
--
|
--
|
||||||
|
-- @returns the processes pid
|
||||||
|
--
|
||||||
function spawn(...)
|
function spawn(...)
|
||||||
local pid = posix.fork()
|
local pid = posix.fork()
|
||||||
if pid < 0 then
|
if pid < 0 then
|
||||||
@ -43,5 +45,3 @@ function spawn(...)
|
|||||||
return pid
|
return pid
|
||||||
end
|
end
|
||||||
|
|
||||||
print(mktempd())
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user