about summary refs log tree commit diff
path: root/tests
blob: 0e664ad78d357a1ebec192d21dc7a6decab9223c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh

: ${NQ:=../nq}
: ${FQ:=../fq}

set -e

check() {
  msg=$1
  shift
  if eval "$@" 2>/dev/null 1>&2; then
    printf 'ok - %s\n' "$msg"
  else
    printf 'not ok - %s\n' "$msg"
    false
  fi
  true
}

printf '1..36\n'

rm -rf test.dir
mkdir test.dir
(
cd test.dir

printf '# nq tests\n'
check 'fails with no arguments' ! $NQ
check 'succeeds enqueuing true' 'f=$($NQ true)'
sleep 1
check 'generated a lockfile' test -f $f
check 'lockfile contains exec line' grep -q exec.*nq.*true $f
check 'lockfile contains status line' grep -q exited.*status.*0 $f
check 'lockfile is not executable' ! test -x $f
)

rm -rf test.dir
mkdir test.dir
(
cd test.dir

printf '# queue tests\n'
check 'enqueing true' f1=$($NQ true)
check 'enqueing sleep 500' f2=$($NQ sleep 500)
check 'first job is done already' $NQ -t $f1
check 'not all jobs are done already' ! $NQ -t
check 'running job is executable' test -x $f2
check 'running job not done already' ! $NQ -t $f
check 'can kill running job' kill ${f2##*.}
sleep 1
check 'killed job is not executable anymore' ! test -x $f2
check 'killed job contains status line' grep -q killed.*signal.*15 $f2
)

rm -rf test.dir
mkdir test.dir
(
cd test.dir

printf '# env tests\n'
check 'enqueing env' f1=$($NQ env)
$NQ -w
check 'NQJOBID is set' grep -q NQJOBID=$f1 $f1
)

rm -rf test.dir
mkdir test.dir
(
cd test.dir

printf '# killing tests\n'
check 'spawning four jobs' 'f1=$($NQ sleep 100)'
check 'spawning four jobs' 'f2=$($NQ sleep 1)'
check 'spawning four jobs' 'f3=$($NQ sleep 100)'
check 'spawning four jobs' 'f4=$($NQ sleep 1)'
check 'killing first job' kill ${f1##*.}
check 'killing third job' kill ${f3##*.}
check 'second job is running' ! $NQ -t $f2
$NQ -w $f2
check 'fourth job is running' ! $NQ -t $f4
check 'all jobs are done' $NQ -w
)

rm -rf test.dir
mkdir test.dir
(
cd test.dir

printf '# fq tests\n'
check 'spawning four jobs' 'f1=$($NQ sleep 100)'
check 'spawning four jobs' 'f2=$($NQ echo two)'
check 'spawning four jobs' 'f3=$($NQ sleep 300)'
check 'spawning four jobs' 'f4=$($NQ sleep 400)'
check 'fq tracks first job' '($FQ ,* & p=$!; sleep 1; kill $p) | sed 3q | grep -q sleep.*100'
check 'killing first job' kill ${f1##*.}
check 'killing fourth job' kill ${f4##*.}
sleep 1
check 'fq tracks third job' '($FQ ,* & p=$!; sleep 1; kill $p) | sed 3q | grep -q sleep.*300'
check 'killing third job' kill ${f3##*.}
sleep 1
check 'fq outputs last job when no job running' '$FQ ,* | sed 3q | grep -q sleep.*400'
)

rm -rf test.dir