| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
: ${NQ:=../nq} |
| 4 |
: ${NQTAIL:=../nqtail} |
| 5 |
|
| 6 |
set -e |
| 7 |
|
| 8 |
check() { |
| 9 |
msg=$1 |
| 10 |
shift |
| 11 |
if eval "$@" 2>/dev/null 1>&2; then |
| 12 |
printf 'ok - %s\n' "$msg" |
| 13 |
else |
| 14 |
printf 'not ok - %s\n' "$msg" |
| 15 |
false |
| 16 |
fi |
| 17 |
true |
| 18 |
} |
| 19 |
|
| 20 |
printf '1..36\n' |
| 21 |
|
| 22 |
rm -rf test.dir |
| 23 |
mkdir test.dir |
| 24 |
( |
| 25 |
cd test.dir |
| 26 |
|
| 27 |
printf '# nq tests\n' |
| 28 |
check 'fails with no arguments' ! $NQ |
| 29 |
check 'succeeds enqueuing true' 'f=$($NQ true)' |
| 30 |
sleep 1 |
| 31 |
check 'generated a lockfile' test -f $f |
| 32 |
check 'lockfile contains exec line' grep -q exec.*nq.*true $f |
| 33 |
check 'lockfile contains status line' grep -q exited.*status.*0 $f |
| 34 |
check 'lockfile is not executable' ! test -x $f |
| 35 |
) |
| 36 |
|
| 37 |
rm -rf test.dir |
| 38 |
mkdir test.dir |
| 39 |
( |
| 40 |
cd test.dir |
| 41 |
|
| 42 |
printf '# queue tests\n' |
| 43 |
check 'enqueing true' f1=$($NQ true) |
| 44 |
check 'enqueing sleep 500' f2=$($NQ sleep 500) |
| 45 |
check 'first job is done already' $NQ -t $f1 |
| 46 |
check 'not all jobs are done already' ! $NQ -t |
| 47 |
check 'running job is executable' test -x $f2 |
| 48 |
check 'running job not done already' ! $NQ -t $f |
| 49 |
check 'can kill running job' kill ${f2##*.} |
| 50 |
sleep 1 |
| 51 |
check 'killed job is not executable anymore' ! test -x $f2 |
| 52 |
check 'killed job contains status line' grep -q killed.*signal.*15 $f2 |
| 53 |
) |
| 54 |
|
| 55 |
rm -rf test.dir |
| 56 |
mkdir test.dir |
| 57 |
( |
| 58 |
cd test.dir |
| 59 |
|
| 60 |
printf '# env tests\n' |
| 61 |
check 'enqueing env' f1=$($NQ env) |
| 62 |
$NQ -w |
| 63 |
check 'NQJOBID is set' grep -q NQJOBID=$f1 $f1 |
| 64 |
) |
| 65 |
|
| 66 |
rm -rf test.dir |
| 67 |
mkdir test.dir |
| 68 |
( |
| 69 |
cd test.dir |
| 70 |
|
| 71 |
printf '# killing tests\n' |
| 72 |
check 'spawning four jobs' 'f1=$($NQ sleep 100)' |
| 73 |
check 'spawning four jobs' 'f2=$($NQ sleep 1)' |
| 74 |
check 'spawning four jobs' 'f3=$($NQ sleep 100)' |
| 75 |
check 'spawning four jobs' 'f4=$($NQ sleep 1)' |
| 76 |
check 'killing first job' kill ${f1##*.} |
| 77 |
check 'killing third job' kill ${f3##*.} |
| 78 |
check 'second job is running' ! $NQ -t $f2 |
| 79 |
$NQ -w $f2 |
| 80 |
check 'fourth job is running' ! $NQ -t $f4 |
| 81 |
check 'all jobs are done' $NQ -w |
| 82 |
) |
| 83 |
|
| 84 |
rm -rf test.dir |
| 85 |
mkdir test.dir |
| 86 |
( |
| 87 |
cd test.dir |
| 88 |
|
| 89 |
printf '# nqtail tests\n' |
| 90 |
check 'spawning four jobs' 'f1=$($NQ sleep 100)' |
| 91 |
check 'spawning four jobs' 'f2=$($NQ echo two)' |
| 92 |
check 'spawning four jobs' 'f3=$($NQ sleep 300)' |
| 93 |
check 'spawning four jobs' 'f4=$($NQ sleep 400)' |
| 94 |
check 'nqtail tracks first job' '($NQTAIL ,* & p=$!; sleep 1; kill $p) | sed 3q | grep -q sleep.*100' |
| 95 |
check 'killing first job' kill ${f1##*.} |
| 96 |
check 'killing fourth job' kill ${f4##*.} |
| 97 |
sleep 1 |
| 98 |
check 'nqtail tracks third job' '($NQTAIL ,* & p=$!; sleep 1; kill $p) | sed 3q | grep -q sleep.*300' |
| 99 |
check 'killing third job' kill ${f3##*.} |
| 100 |
sleep 1 |
| 101 |
check 'nqtail outputs last job when no job running' '$NQTAIL ,* | sed 3q | grep -q sleep.*400' |
| 102 |
) |
| 103 |
|
| 104 |
rm -rf test.dir |