reworking tests

This commit is contained in:
Axel Kittenberger 2016-12-21 14:21:32 +01:00
parent 837a3cd927
commit ee50768743
4 changed files with 89 additions and 57 deletions

View File

@ -3,6 +3,7 @@
-- makes thousends of random changes to the source tree -- makes thousends of random changes to the source tree
require( 'posix' ) require( 'posix' )
dofile( 'tests/testlib.lua' ) dofile( 'tests/testlib.lua' )
cwriteln( '****************************************************************' ) cwriteln( '****************************************************************' )
@ -12,7 +13,7 @@ cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps( ) local tdir, srcdir, trgdir = mktemps( )
-- makes some startup data -- makes some startup data
churn( srcdir, 10 ) churn( srcdir, 10, init )
local logs = { } local logs = { }
--local logs = {'-log', 'Exec', '-log', 'Delay' } --local logs = {'-log', 'Exec', '-log', 'Delay' }
@ -26,7 +27,7 @@ local pid = spawn(
cwriteln( 'waiting for Lsyncd to startup' ) cwriteln( 'waiting for Lsyncd to startup' )
posix.sleep( 1 ) posix.sleep( 1 )
churn( srcdir, 500 ) churn( srcdir, 500, false )
cwriteln( 'waiting for Lsyncd to finish its jobs.' ) cwriteln( 'waiting for Lsyncd to finish its jobs.' )
posix.sleep( 10 ) posix.sleep( 10 )

View File

@ -11,7 +11,7 @@ cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps( ) local tdir, srcdir, trgdir = mktemps( )
-- makes some startup data -- makes some startup data
churn( srcdir, 100 ) churn( srcdir, 100, true )
local logs = { } local logs = { }
-- logs = { "-log", "Delay", "-log", "Fsevents" } -- logs = { "-log", "Delay", "-log", "Fsevents" }
@ -27,7 +27,7 @@ cwriteln( 'waiting for Lsyncd to startup' )
posix.sleep( 1 ) posix.sleep( 1 )
churn( srcdir, 500 ) churn( srcdir, 500, false )
cwriteln( 'waiting for Lsyncd to finish its jobs.' ) cwriteln( 'waiting for Lsyncd to finish its jobs.' )

View File

@ -15,7 +15,7 @@ cwriteln( '( for current user )' )
local tdir, srcdir, trgdir = mktemps() local tdir, srcdir, trgdir = mktemps()
-- makes some startup data -- makes some startup data
churn( srcdir, 100 ) churn( srcdir, 10, true )
local logs = {} local logs = {}
logs = { '-log', 'Delay' } logs = { '-log', 'Delay' }
@ -35,7 +35,7 @@ local pid = spawn(
cwriteln( 'waiting for Lsyncd to startup' ) cwriteln( 'waiting for Lsyncd to startup' )
posix.sleep( 1 ) posix.sleep( 1 )
churn( srcdir, 100 ) churn( srcdir, 15, false )
cwriteln( 'waiting for Lsyncd to finish its jobs.' ) cwriteln( 'waiting for Lsyncd to finish its jobs.' )
posix.sleep( 10 ) posix.sleep( 10 )

View File

@ -3,19 +3,24 @@ 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'
-- --
-- writes colorized -- Writes colorized.
-- --
function cwriteln(...) function cwriteln
(...)
io.write( c1, '++ ', ... ) io.write( c1, '++ ', ... )
io.write( c0, '\n' ) io.write( c0, '\n' )
end end
-- --
-- initializes the pseudo random generator -- Initializes the pseudo random generator
-- if environemnt 'SEED' is set, use that as seed. --
-- If environment variable 'SEED' is set,
-- that one is used seed.
--
local seed = os.getenv( 'SEED') or os.time( ) local seed = os.getenv( 'SEED') or os.time( )
math.randomseed( seed ) math.randomseed( seed )
@ -23,12 +28,12 @@ math.randomseed( seed )
cwriteln( 'random seed: ', seed ) cwriteln( 'random seed: ', seed )
-- --
-- creates a tmp directory -- Creates a tmp directory.
-- --
-- @returns the name of the directory -- Returns the name of the directory.
-- --
function mktempd( ) function mktempd
( )
local f = io.popen( 'mktemp -td ltest.XXX', 'r' ) local f = io.popen( 'mktemp -td ltest.XXX', 'r' )
local s = f:read( '*a' ) local s = f:read( '*a' )
@ -43,15 +48,15 @@ function mktempd( )
end end
-- --
-- creates a tmp directory with the -- Creates a tmp directory with the
-- typical lsyncd test architecture -- typical lsyncd test architecture.
-- --
-- @returns path of tmpdir -- returns path of tmpdir
-- path of srcdir -- path of srcdir
-- path of trgdir -- path of trgdir
-- --
function mktemps
function mktemps( ) ( )
local tdir = mktempd() .. '/' local tdir = mktempd() .. '/'
cwriteln( 'using ', tdir, ' as test root' ) cwriteln( 'using ', tdir, ' as test root' )
@ -71,8 +76,11 @@ end
-- Writes a file with 'text' in it -- Writes a file with 'text' in it
-- and adds a newline. -- and adds a newline.
-- --
function writefile( filename, text ) function writefile
(
filename,
text
)
local f = io.open( filename, 'w' ) local f = io.open( filename, 'w' )
if not f if not f
@ -91,12 +99,12 @@ function writefile( filename, text )
end end
-- --
-- spawns a subprocess. -- Spawns a subprocess.
-- --
-- @returns the processes pid -- Returns the processes pid.
-- --
function spawn(...) function spawn
(...)
args = { ... } args = { ... }
cwriteln( 'spawning: ', table.concat( args, ' ' ) ) cwriteln( 'spawning: ', table.concat( args, ' ' ) )
@ -126,11 +134,13 @@ end
-- --
-- Makes a lot of random data -- Makes a lot of random data
-- --
-- @param rootdir ... the directory to make data in
-- @param n ... roughly how much data action will done
-- --
function churn( rootdir, n ) function churn
(
rootdir, -- the directory to make data in
n, -- roughly how much data action will be done
init -- if true init random data only, no sleeps or moves
)
-- all dirs created, indexed by integer and path -- all dirs created, indexed by integer and path
root = { name = '' } root = { name = '' }
@ -145,7 +155,11 @@ function churn( rootdir, n )
-- --
-- name is internal recursive paramter, keep it nil. -- name is internal recursive paramter, keep it nil.
-- --
local function dirname( dir, name ) local function dirname
(
dir,
name
)
name = name or '' name = name or ''
if not dir if not dir
@ -159,7 +173,10 @@ function churn( rootdir, n )
-- --
-- Picks a random dir. -- Picks a random dir.
-- --
local function pickDir( notRoot ) local function pickDir
(
notRoot
)
if notRoot if notRoot
then then
if #alldirs <= 2 if #alldirs <= 2
@ -181,8 +198,8 @@ function churn( rootdir, n )
-- * the filename -- * the filename
-- * number of files in directory -- * number of files in directory
-- --
local function pickFile( ) local function pickFile
( )
-- picks the random directory -- picks the random directory
if #dirsWithFileI < 1 if #dirsWithFileI < 1
then then
@ -236,8 +253,8 @@ function churn( rootdir, n )
-- @param fn -- filename -- @param fn -- filename
-- @param c -- number of files in dir -- @param c -- number of files in dir
-- --
local function rmFileReference( dir, fn, c ) local function rmFileReference
( dir, fn, c )
dir[fn] = nil dir[fn] = nil
if c == 1 if c == 1
@ -261,7 +278,8 @@ function churn( rootdir, n )
-- possible randomized behaviour. -- possible randomized behaviour.
-- just gives it a pause -- just gives it a pause
-- --
local function sleep( ) local function sleep
( )
cwriteln( '..zzz..' ) cwriteln( '..zzz..' )
posix.sleep( 1 ) posix.sleep( 1 )
@ -271,8 +289,8 @@ function churn( rootdir, n )
-- possible randomized behaviour. -- possible randomized behaviour.
-- creates a directory -- creates a directory
-- --
local function mkdir( ) local function mkdir
( )
-- chooses a random directory to create it into -- chooses a random directory to create it into
local rdir = pickDir( ) local rdir = pickDir( )
@ -299,11 +317,11 @@ function churn( rootdir, n )
end end
-- --
-- possible randomized behaviour. -- Possible randomized behaviour:
-- Creates a file. -- Creates a file.
-- --
local function mkfile( ) local function mkfile
( )
-- chooses a random directory to create it into -- chooses a random directory to create it into
local rdir = pickDir() local rdir = pickDir()
@ -342,8 +360,8 @@ function churn( rootdir, n )
-- Possible randomized behaviour: -- Possible randomized behaviour:
-- Moves a directory. -- Moves a directory.
-- --
local function mvdir( ) local function mvdir
( )
if #alldirs <= 2 if #alldirs <= 2
then then
return return
@ -393,7 +411,8 @@ function churn( rootdir, n )
-- possible randomized behaviour, -- possible randomized behaviour,
-- moves a file. -- moves a file.
-- --
local function mvfile( ) local function mvfile
( )
local odir, fn, c = pickFile( ) local odir, fn, c = pickFile( )
if not odir if not odir
@ -425,11 +444,11 @@ function churn( rootdir, n )
end end
-- --
-- possible randomized behaviour, -- Possible randomized behaviour:
-- removes a file. -- Removes a file.
-- --
local function rmfile( ) local function rmfile
( )
local dir, fn, c = pickFile( ) local dir, fn, c = pickFile( )
if dir if dir
@ -444,13 +463,25 @@ function churn( rootdir, n )
end end
end end
local dice = { local dice
{ 10, sleep },
{ 20, mkfile }, if init
{ 20, mkdir }, then
{ 20, mvdir }, dice =
{ 20, rmfile }, {
} { 10, mkfile },
{ 10, mkdir },
}
else
dice =
{
{ 10, sleep },
{ 20, mkfile },
{ 20, mkdir },
{ 20, mvdir },
{ 20, rmfile },
}
end
cwriteln( 'making random data' ) cwriteln( 'making random data' )