mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-05 16:12:32 +00:00
fixing tests for lua 5.2 os.execute call semantics
This commit is contained in:
parent
1f95925304
commit
2493476f64
@ -2,17 +2,17 @@
|
||||
-- a heavy duty test.
|
||||
-- makes thousends of random changes to the source tree
|
||||
|
||||
require('posix')
|
||||
dofile('tests/testlib.lua')
|
||||
require( 'posix' )
|
||||
dofile( 'tests/testlib.lua' )
|
||||
|
||||
cwriteln('****************************************************************')
|
||||
cwriteln(' Testing default.direct with random data activity ')
|
||||
cwriteln('****************************************************************')
|
||||
cwriteln( '****************************************************************' )
|
||||
cwriteln( ' Testing default.direct with random data activity ' )
|
||||
cwriteln( '****************************************************************' )
|
||||
|
||||
local tdir, srcdir, trgdir = mktemps()
|
||||
local tdir, srcdir, trgdir = mktemps( )
|
||||
|
||||
-- makes some startup data
|
||||
churn(srcdir, 10)
|
||||
churn( srcdir, 10 )
|
||||
|
||||
local logs = { }
|
||||
--local logs = {'-log', 'Exec', '-log', 'Delay' }
|
||||
@ -20,24 +20,36 @@ local pid = spawn(
|
||||
'./lsyncd',
|
||||
'-nodaemon',
|
||||
'-direct', srcdir, trgdir,
|
||||
unpack(logs)
|
||||
unpack( logs )
|
||||
)
|
||||
|
||||
cwriteln('waiting for Lsyncd to startup')
|
||||
posix.sleep(1)
|
||||
cwriteln( 'waiting for Lsyncd to startup' )
|
||||
posix.sleep( 1 )
|
||||
|
||||
churn(srcdir, 500)
|
||||
churn( srcdir, 500 )
|
||||
|
||||
cwriteln('waiting for Lsyncd to finish its jobs.')
|
||||
posix.sleep(10)
|
||||
cwriteln( 'waiting for Lsyncd to finish its jobs.' )
|
||||
posix.sleep( 10 )
|
||||
|
||||
cwriteln('killing the Lsyncd daemon')
|
||||
posix.kill(pid)
|
||||
local _, exitmsg, lexitcode = posix.wait(lpid)
|
||||
cwriteln('Exitcode of Lsyncd = ',exitmsg,' ',lexitcode)
|
||||
cwriteln( 'killing the Lsyncd daemon' )
|
||||
posix.kill( pid )
|
||||
|
||||
exitcode = os.execute('diff -r '..srcdir..' '..trgdir)
|
||||
cwriteln('Exitcode of diff = "', exitcode, '"')
|
||||
local _, exitmsg, lexitcode = posix.wait( lpid )
|
||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
|
||||
|
||||
if exitcode ~= 0 then os.exit(1) else os.exit(0) end
|
||||
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
|
||||
|
||||
if result == 'exit'
|
||||
then
|
||||
cwriteln( 'Exitcode of diff = ', code )
|
||||
else
|
||||
cwriteln( 'Signal terminating diff = ', code )
|
||||
end
|
||||
|
||||
if code ~= 0
|
||||
then
|
||||
os.exit( 1 )
|
||||
else
|
||||
os.exit( 0 )
|
||||
end
|
||||
|
||||
|
@ -39,10 +39,17 @@ posix.kill( pid )
|
||||
local _, exitmsg, lexitcode = posix.wait( lpid )
|
||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
|
||||
|
||||
exitcode = os.execute( 'diff -r '..srcdir..' '..trgdir )
|
||||
cwriteln( 'Exitcode of diff = "', exitcode, '"' )
|
||||
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
|
||||
|
||||
if exitcode ~= 0 then
|
||||
if result == 'exit'
|
||||
then
|
||||
cwriteln( 'Exitcode of diff = ', code )
|
||||
else
|
||||
cwriteln( 'Signal terminating diff = ', code )
|
||||
end
|
||||
|
||||
if exitcode ~= 0
|
||||
then
|
||||
os.exit( 1 )
|
||||
else
|
||||
os.exit( 0 )
|
||||
|
@ -45,10 +45,17 @@ posix.kill(pid)
|
||||
local _, exitmsg, lexitcode = posix.wait(lpid)
|
||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
|
||||
|
||||
exitcode = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
|
||||
cwriteln( 'Exitcode of diff = "', exitcode, '"' )
|
||||
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
|
||||
|
||||
if exitcode ~= 0 then
|
||||
if result == 'exit'
|
||||
then
|
||||
cwriteln( 'Exitcode of diff = ', code )
|
||||
else
|
||||
cwriteln( 'Signal terminating diff = ', code )
|
||||
end
|
||||
|
||||
if exitcode ~= 0
|
||||
then
|
||||
os.exit( 1 )
|
||||
else
|
||||
os.exit( 0 )
|
||||
|
@ -14,17 +14,17 @@ local log = {"-log", "all"}
|
||||
|
||||
writefile(cfgfile, [[
|
||||
settings = {
|
||||
logfile = "]]..logfile..[[",
|
||||
nodaemon = true,
|
||||
logfile = "]]..logfile..[[",
|
||||
nodaemon = true,
|
||||
delay = 3,
|
||||
}
|
||||
|
||||
sync {
|
||||
default.rsync,
|
||||
default.rsync,
|
||||
source = "]]..srcdir..[[",
|
||||
target = "]]..trgdir..[[",
|
||||
exclude = {
|
||||
"erf",
|
||||
"erf",
|
||||
"/eaf",
|
||||
"erd/",
|
||||
"/ead/",
|
||||
@ -70,42 +70,51 @@ local function testfiles()
|
||||
end
|
||||
|
||||
|
||||
cwriteln("testing startup excludes");
|
||||
writefiles();
|
||||
cwriteln("starting Lsyncd");
|
||||
local pid = spawn("./lsyncd", cfgfile, '-log', 'all');
|
||||
cwriteln("waiting for Lsyncd to start");
|
||||
posix.sleep(3)
|
||||
cwriteln("testing excludes after startup");
|
||||
testfiles();
|
||||
cwriteln("ok, removing sources");
|
||||
|
||||
if srcdir:sub(1,4) ~= "/tmp" then
|
||||
-- just to make sure before rm -rf
|
||||
cwriteln("exist before drama, srcdir is '", srcdir, "'");
|
||||
os.exit(1);
|
||||
end
|
||||
|
||||
os.execute("rm -rf "..srcdir.."/*");
|
||||
cwriteln("waiting for Lsyncd to remove destination");
|
||||
posix.sleep(5);
|
||||
if os.execute("diff -urN "..srcdir.." "..trgdir) ~= 0 then
|
||||
cwriteln("fail, target directory not empty!");
|
||||
os.exit(1);
|
||||
end
|
||||
|
||||
cwriteln( "writing files after startup" );
|
||||
cwriteln( 'testing startup excludes' );
|
||||
writefiles( );
|
||||
cwriteln( "waiting for Lsyncd to transmit changes" );
|
||||
cwriteln( 'starting Lsyncd' );
|
||||
local pid = spawn( './lsyncd', cfgfile, '-log', 'all');
|
||||
|
||||
cwriteln( 'waiting for Lsyncd to start' );
|
||||
posix.sleep( 3 )
|
||||
cwriteln( 'testing excludes after startup' );
|
||||
testfiles( );
|
||||
cwriteln( 'ok, removing sources' );
|
||||
|
||||
if srcdir:sub( 1,4 ) ~= '/tmp'
|
||||
then
|
||||
-- just to make sure before rm -rf
|
||||
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' );
|
||||
os.exit( 1 );
|
||||
end
|
||||
|
||||
os.execute( 'rm -rf '..srcdir..'/*' );
|
||||
|
||||
cwriteln( 'waiting for Lsyncd to remove destination' );
|
||||
|
||||
posix.sleep( 5 );
|
||||
|
||||
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
|
||||
|
||||
if result ~= 'exit' or code ~= 0
|
||||
then
|
||||
cwriteln( 'fail, target directory not empty!' );
|
||||
os.exit( 1 );
|
||||
end
|
||||
|
||||
cwriteln( 'writing files after startup' );
|
||||
writefiles( );
|
||||
cwriteln( 'waiting for Lsyncd to transmit changes' );
|
||||
posix.sleep( 5 );
|
||||
testfiles( );
|
||||
|
||||
cwriteln( "killing started Lsyncd" );
|
||||
cwriteln( 'killing started Lsyncd' );
|
||||
posix.kill( pid );
|
||||
local _, exitmsg, lexitcode = posix.wait( lpid );
|
||||
cwriteln( "Exitcode of Lsyncd = ", exitmsg, " ", lexitcode );
|
||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode );
|
||||
|
||||
if lexitcode == 143 then
|
||||
if lexitcode == 143
|
||||
then
|
||||
cwriteln( "OK" );
|
||||
os.exit( 0 );
|
||||
else
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
require('posix')
|
||||
dofile('tests/testlib.lua')
|
||||
require( 'posix' )
|
||||
dofile( 'tests/testlib.lua' )
|
||||
|
||||
cwriteln('****************************************************************');
|
||||
cwriteln(' Testing excludes');
|
||||
cwriteln('****************************************************************');
|
||||
cwriteln(' (this test needs passwordless ssh localhost access ');
|
||||
cwriteln(' for current user)');
|
||||
cwriteln( '****************************************************************' );
|
||||
cwriteln( ' Testing excludes' );
|
||||
cwriteln( '****************************************************************' );
|
||||
cwriteln( ' (this test needs passwordless ssh localhost access ' );
|
||||
cwriteln( ' for current user)' );
|
||||
|
||||
local tdir, srcdir, trgdir = mktemps()
|
||||
local tdir, srcdir, trgdir = mktemps( )
|
||||
local logfile = tdir .. 'log'
|
||||
local cfgfile = tdir .. 'config.lua'
|
||||
local range = 5
|
||||
@ -18,18 +18,18 @@ log = {'-log', 'all'}
|
||||
|
||||
writefile(cfgfile, [[
|
||||
settings = {
|
||||
logfile = ']]..logfile..[[',
|
||||
nodaemon = true,
|
||||
logfile = ']]..logfile..[[',
|
||||
nodaemon = true,
|
||||
delay = 3,
|
||||
}
|
||||
|
||||
sync {
|
||||
default.rsyncssh,
|
||||
default.rsyncssh,
|
||||
host = 'localhost',
|
||||
source = ']]..srcdir..[[',
|
||||
targetdir = ']]..trgdir..[[',
|
||||
exclude = {
|
||||
'erf',
|
||||
'erf',
|
||||
'/eaf',
|
||||
'erd/',
|
||||
'/ead/',
|
||||
@ -64,14 +64,14 @@ end
|
||||
|
||||
-- test all files
|
||||
local function testfiles()
|
||||
testfile(trgdir .. 'erf', false);
|
||||
testfile(trgdir .. 'eaf', false);
|
||||
testfile(trgdir .. 'erd', true);
|
||||
testfile(trgdir .. 'ead', true);
|
||||
testfile(trgdir .. 'd/erf', false);
|
||||
testfile(trgdir .. 'd/eaf', true);
|
||||
testfile(trgdir .. 'd/erd', true);
|
||||
testfile(trgdir .. 'd/ead', true);
|
||||
testfile( trgdir .. 'erf', false );
|
||||
testfile( trgdir .. 'eaf', false );
|
||||
testfile( trgdir .. 'erd', true );
|
||||
testfile( trgdir .. 'ead', true );
|
||||
testfile( trgdir .. 'd/erf', false );
|
||||
testfile( trgdir .. 'd/eaf', true );
|
||||
testfile( trgdir .. 'd/erd', true );
|
||||
testfile( trgdir .. 'd/ead', true );
|
||||
end
|
||||
|
||||
|
||||
@ -89,27 +89,33 @@ if srcdir:sub(1,4) ~= '/tmp' then
|
||||
cwriteln('exist before drama, srcdir is "', srcdir, '"');
|
||||
os.exit(1);
|
||||
end
|
||||
os.execute('rm -rf '..srcdir..'/*');
|
||||
cwriteln('waiting for Lsyncd to remove destination');
|
||||
posix.sleep(5);
|
||||
if os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0 then
|
||||
cwriteln('fail, target directory not empty!');
|
||||
os.exit(1);
|
||||
|
||||
os.execute( 'rm -rf ' .. srcdir .. '/*' );
|
||||
cwriteln( 'waiting for Lsyncd to remove destination' );
|
||||
posix.sleep( 5 );
|
||||
|
||||
_, result, code = os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0
|
||||
|
||||
if result ~= 'exit' or code ~= 0
|
||||
then
|
||||
cwriteln( 'fail, target directory not empty!' );
|
||||
os.exit( 1 );
|
||||
end
|
||||
|
||||
cwriteln('writing files after startup');
|
||||
writefiles();
|
||||
cwriteln('waiting for Lsyncd to transmit changes');
|
||||
posix.sleep(15);
|
||||
testfiles();
|
||||
cwriteln( 'writing files after startup' );
|
||||
writefiles( );
|
||||
cwriteln( 'waiting for Lsyncd to transmit changes' );
|
||||
posix.sleep( 15 );
|
||||
testfiles( );
|
||||
|
||||
cwriteln('killing started Lsyncd');
|
||||
posix.kill(pid);
|
||||
local _, exitmsg, lexitcode = posix.wait(lpid);
|
||||
cwriteln('Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode);
|
||||
posix.sleep(1);
|
||||
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
|
||||
if lexitcode == 143
|
||||
then
|
||||
cwriteln( 'OK' );
|
||||
os.exit( 0 );
|
||||
else
|
||||
|
@ -1,34 +1,46 @@
|
||||
#!/usr/bin/lua
|
||||
require("posix")
|
||||
dofile("tests/testlib.lua")
|
||||
require( 'posix' )
|
||||
dofile( 'tests/testlib.lua' )
|
||||
|
||||
cwriteln("****************************************************************")
|
||||
cwriteln(" Testing layer 4 default rsync with simulated data activity ")
|
||||
cwriteln("****************************************************************")
|
||||
cwriteln( '****************************************************************' )
|
||||
cwriteln( ' Testing layer 4 default rsync with simulated data activity ' )
|
||||
cwriteln( '****************************************************************' )
|
||||
|
||||
local tdir, srcdir, trgdir = mktemps()
|
||||
local logfile = tdir .. "log"
|
||||
local logfile = tdir .. 'log'
|
||||
local range = 5
|
||||
local log = {"-log", "all"}
|
||||
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)
|
||||
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")
|
||||
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)
|
||||
logs = { }
|
||||
local pid =
|
||||
spawn(
|
||||
'./lsyncd',
|
||||
'-logfile', logfile,
|
||||
'-nodaemon',
|
||||
'-delay', '5',
|
||||
"-rsync", srcdir, trgdir,
|
||||
unpack( logs )
|
||||
)
|
||||
|
||||
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)
|
||||
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
|
||||
@ -38,23 +50,31 @@ end
|
||||
-- echo 'test4' > "$S"/m${i}/n/another
|
||||
-- done
|
||||
|
||||
cwriteln("* waiting for Lsyncd to do its job.")
|
||||
posix.sleep(10)
|
||||
cwriteln( '* waiting for Lsyncd to do its job.' )
|
||||
posix.sleep( 10 )
|
||||
|
||||
cwriteln("* killing Lsyncd")
|
||||
cwriteln( '* killing Lsyncd' )
|
||||
|
||||
posix.kill(pid)
|
||||
posix.kill( pid )
|
||||
local _, exitmsg, lexitcode = posix.wait(lpid)
|
||||
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", lexitcode)
|
||||
posix.sleep(1)
|
||||
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode)
|
||||
posix.sleep( 1 )
|
||||
|
||||
cwriteln("* differences:")
|
||||
exitcode = os.execute("diff -urN "..srcdir.." "..trgdir)
|
||||
cwriteln("Exitcode of diff = '", exitcode, "'")
|
||||
if exitcode ~= 0 then
|
||||
os.exit(1)
|
||||
cwriteln( '* differences:' )
|
||||
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
|
||||
|
||||
if result == 'exit'
|
||||
then
|
||||
cwriteln( 'Exitcode of diff = "', code, '"')
|
||||
else
|
||||
os.exit(0)
|
||||
cwriteln( 'Signal terminating diff = "', code, '"')
|
||||
end
|
||||
|
||||
if result ~= 'exit' or exitcode ~= 0
|
||||
then
|
||||
os.exit( 1 )
|
||||
else
|
||||
os.exit( 0 )
|
||||
end
|
||||
|
||||
-- TODO remove temp
|
||||
|
@ -1,5 +1,5 @@
|
||||
-- common testing environment
|
||||
require('posix')
|
||||
posix = require('posix')
|
||||
|
||||
-- escape codes to colorize output on terminal
|
||||
local c1='\027[47;34m'
|
||||
|
Loading…
Reference in New Issue
Block a user