2018-03-09 10:07:53 +00:00
|
|
|
require( 'posix' )
|
|
|
|
dofile( 'tests/testlib.lua' )
|
2011-08-18 13:29:18 +00:00
|
|
|
|
2018-03-09 10:07:53 +00:00
|
|
|
cwriteln( '****************************************************************' )
|
|
|
|
cwriteln( ' Testing Lsyncd scheduler ' )
|
|
|
|
cwriteln( '****************************************************************' )
|
2011-08-18 13:29:18 +00:00
|
|
|
|
|
|
|
local tdir, srcdir, trgdir = mktemps()
|
|
|
|
local logfile = tdir .. "log"
|
|
|
|
local cfgfile = tdir .. "config.lua"
|
|
|
|
local logs = {"-log", "all" }
|
|
|
|
|
|
|
|
writefile(cfgfile, [[
|
2017-01-04 11:23:22 +00:00
|
|
|
settings {
|
|
|
|
logfile = "]]..logfile..[[",
|
2011-08-18 13:29:18 +00:00
|
|
|
log = all,
|
2017-01-04 11:23:22 +00:00
|
|
|
nodaemon = true,
|
2011-08-18 13:29:18 +00:00
|
|
|
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
|
2018-03-09 10:07:53 +00:00
|
|
|
local function testfile
|
|
|
|
(
|
|
|
|
filename
|
|
|
|
)
|
2011-08-18 13:29:18 +00:00
|
|
|
local stat, err = posix.stat(filename)
|
2018-03-09 10:07:53 +00:00
|
|
|
|
|
|
|
if not stat
|
|
|
|
then
|
|
|
|
cwriteln( 'failure: ', filename, ' missing' )
|
|
|
|
os.exit( 1 )
|
2011-08-18 13:29:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-09 10:07:53 +00:00
|
|
|
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)
|
2011-08-18 13:29:18 +00:00
|
|
|
posix.sleep(1);
|
2012-10-07 18:48:09 +00:00
|
|
|
|
2018-03-09 10:07:53 +00:00
|
|
|
if lexitcode == 143
|
|
|
|
then
|
|
|
|
cwriteln( 'OK' )
|
2012-10-07 18:48:09 +00:00
|
|
|
os.exit( 0 )
|
|
|
|
else
|
|
|
|
os.exit( 1 )
|
2011-08-18 13:29:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO remove temp
|