fixing test

This commit is contained in:
Axel Kittenberger 2017-01-04 12:32:10 +01:00
parent ac5ef0474e
commit f6f360b9dc
1 changed files with 66 additions and 53 deletions

View File

@ -37,64 +37,77 @@ sync {
}]]); }]]);
-- writes all files -- writes all files
local function writefiles() local function writefiles
posix.mkdir(srcdir .. 'd'); ( )
writefile(srcdir .. 'erf', 'erf'); posix.mkdir( srcdir .. 'd' )
writefile(srcdir .. 'eaf', 'erf'); writefile( srcdir .. 'erf', 'erf' )
writefile(srcdir .. 'erd', 'erd'); writefile( srcdir .. 'eaf', 'erf' )
writefile(srcdir .. 'ead', 'ead'); writefile( srcdir .. 'erd', 'erd' )
writefile(srcdir .. 'd/erf', 'erf'); writefile( srcdir .. 'ead', 'ead' )
writefile(srcdir .. 'd/eaf', 'erf'); writefile( srcdir .. 'd/erf', 'erf' )
writefile(srcdir .. 'd/erd', 'erd'); writefile( srcdir .. 'd/eaf', 'erf' )
writefile(srcdir .. 'd/ead', 'ead'); writefile( srcdir .. 'd/erd', 'erd' )
writefile( srcdir .. 'd/ead', 'ead' )
end end
-- test if the filename exists, fails if this is different to expect -- test if the filename exists, fails if this is different to expect
local function testfile(filename, expect) local function testfile
local stat, err = posix.stat(filename) (
if stat and not expect then filename,
cwriteln('failure: ',filename,' should be excluded'); expect
os.exit(1); )
local stat, err = posix.stat( filename )
if stat and not expect
then
cwriteln( 'failure: ',filename,' should be excluded' );
os.exit( 1 );
end end
if not stat and expect then
cwriteln('failure: ',filename,' should not be excluded'); if not stat and expect
os.exit(1); then
cwriteln( 'failure: ',filename,' should not be excluded' );
os.exit( 1 );
end end
end end
-- test all files -- test all files
local function testfiles() local function testfiles
testfile( trgdir .. 'erf', false ); ( )
testfile( trgdir .. 'eaf', false ); testfile( trgdir .. 'erf', false )
testfile( trgdir .. 'erd', true ); testfile( trgdir .. 'eaf', false )
testfile( trgdir .. 'ead', true ); testfile( trgdir .. 'erd', true )
testfile( trgdir .. 'd/erf', false ); testfile( trgdir .. 'ead', true )
testfile( trgdir .. 'd/eaf', true ); testfile( trgdir .. 'd/erf', false )
testfile( trgdir .. 'd/erd', true ); testfile( trgdir .. 'd/eaf', true )
testfile( trgdir .. 'd/ead', true ); testfile( trgdir .. 'd/erd', true )
testfile( trgdir .. 'd/ead', true )
end end
cwriteln('testing startup excludes'); cwriteln( 'testing startup excludes' )
writefiles(); writefiles( )
cwriteln('starting Lsyncd'); cwriteln( 'starting Lsyncd' )
local pid = spawn('./lsyncd', cfgfile, unpack(log)); local pid = spawn( './lsyncd', cfgfile, unpack( log ) )
cwriteln('waiting for Lsyncd to start'); cwriteln( 'waiting for Lsyncd to start' )
posix.sleep(10) posix.sleep( 10 )
cwriteln('testing excludes after startup'); cwriteln( 'testing excludes after startup' )
testfiles(); testfiles( )
cwriteln('ok, removing sources'); cwriteln( 'ok, removing sources' )
if srcdir:sub(1,4) ~= '/tmp' then
if srcdir:sub(1,4) ~= '/tmp'
then
-- just to make sure before rm -rf -- just to make sure before rm -rf
cwriteln('exist before drama, srcdir is "', srcdir, '"'); cwriteln('exit before drama, srcdir is "', srcdir, '"')
os.exit(1);
os.exit( 1 )
end end
os.execute( 'rm -rf ' .. srcdir .. '/*' ); os.execute( 'rm -rf ' .. srcdir .. '/*' )
cwriteln( 'waiting for Lsyncd to remove destination' ); cwriteln( 'waiting for Lsyncd to remove destination' )
posix.sleep( 5 ); posix.sleep( 5 )
_, result, code = os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0 _, result, code = os.execute( 'diff -urN '..srcdir..' '..trgdir )
if result ~= 'exit' or code ~= 0 if result ~= 'exit' or code ~= 0
then then
@ -102,17 +115,17 @@ then
os.exit( 1 ); os.exit( 1 );
end end
cwriteln( 'writing files after startup' ); cwriteln( 'writing files after startup' )
writefiles( ); writefiles( )
cwriteln( 'waiting for Lsyncd to transmit changes' ); cwriteln( 'waiting for Lsyncd to transmit changes' )
posix.sleep( 15 ); posix.sleep( 15 )
testfiles( ); testfiles( )
cwriteln( 'killing started Lsyncd' ); cwriteln( 'killing started Lsyncd' )
posix.kill( pid ); posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait( lpid ); local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ); cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
posix.sleep( 1 ); posix.sleep( 1 )
if lexitcode == 143 if lexitcode == 143
then then