1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
require( 'posix' )
dofile( 'tests/testlib.lua' )
cwriteln( '****************************************************************' )
cwriteln( ' Testing Lsyncd scheduler ' )
cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps()
local logfile = tdir .. "log"
local cfgfile = tdir .. "config.lua"
local logs = {"-log", "all" }
writefile(cfgfile, [[
settings {
logfile = "]]..logfile..[[",
log = all,
nodaemon = true,
maxProcesses = 1
}
-- continously touches a file
acircuit = {
delay = 0,
onStartup = "sleep 3 && touch ^source/a",
onCreate = "sleep 3 && touch ^source/a",
}
-- continously touches b file
bcircuit = {
delay = 0,
onStartup = "sleep 3 && touch ^source/b",
onCreate = "sleep 3 && touch ^source/b",
}
-- continously touches c file
ccircuit = {
delay = 0,
onStartup = "sleep 3 && touch ^source/c",
onCreate = "sleep 3 && touch ^source/c",
}
sync {acircuit, source ="]]..srcdir..[[", target = "]]..trgdir..[["}
sync {bcircuit, source ="]]..srcdir..[[", target = "]]..trgdir..[["}
sync {ccircuit, source ="]]..srcdir..[[", target = "]]..trgdir..[["}
]]);
-- test if the filename exists, fails if this is different to expect
local function testfile
(
filename
)
local stat, err = posix.stat(filename)
if not stat
then
cwriteln( 'failure: ', filename, ' missing' )
os.exit( 1 )
end
end
cwriteln( 'starting Lsyncd' )
local pid = spawn( './lsyncd', cfgfile, table.unpack( logs ) )
cwriteln( 'waiting for Lsyncd to do a few cycles' )
posix.sleep( 30 )
cwriteln( 'look if every circle got a chance to run' )
testfile( srcdir..'a' )
testfile( srcdir..'b' )
testfile( srcdir..'c' )
cwriteln( 'killing started Lsyncd' )
posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode)
posix.sleep(1);
if lexitcode == 143
then
cwriteln( 'OK' )
os.exit( 0 )
else
os.exit( 1 )
end
-- TODO remove temp
|