t/010-jobserver: add serial/parallel override tests.

This new test validates that you can pass -j1 and -j2 in a sub-redo to
create a sub-jobserver with exactly the number of jobs you specified.
Now that we have that feature, we can also test for the bug fixed two
commits ago where, with -j1, targets would be built in an unexpected
order.
This commit is contained in:
Avery Pennarun 2018-12-31 17:43:03 -05:00
commit 87bac287b6
14 changed files with 87 additions and 2 deletions

6
t/010-jobserver/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
*.end
*.start
*.sub
*.spin
*.log
*.x

13
t/010-jobserver/all.do Normal file
View file

@ -0,0 +1,13 @@
# We put the -j options at this toplevel to detect an earlier bug
# where the sub-jobserver wasn't inherited by sub-sub-processes, which
# accidentally reverted to the parent jobserver instead.
redo -j1 serialtest
# Capture log output to parallel.log to hide the (intentional since we're
# testing it) scary warning from redo about overriding the jobserver.
echo 'parallel test...' >&2
if ! redo -j10 paralleltest 2>parallel.log; then
cat parallel.log >&2
exit 99
fi

2
t/010-jobserver/clean.do Normal file
View file

@ -0,0 +1,2 @@
rm -f *~ .*~ *.log *.sub *.spin *.x *.start *.end \
first second parallel parallel2

View file

@ -0,0 +1,4 @@
for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
redo $2.$d.x
done
echo hello

View file

@ -0,0 +1 @@
echo world

24
t/010-jobserver/first.do Normal file
View file

@ -0,0 +1,24 @@
# in case we're (erroneously) running in parallel, give second.do some
# time to start but not finish.
echo 'first sleep' >&2
sleep 1
# Because of --shuffle, we can't be sure if first or second ran first, but
# because all.do uses -j1, we *should* expect that if second ran first, it
# at least ran to completion before we ran at all.
if [ -e second.start ]; then
echo 'first: second already started before we did...' >&2
[ -e second.end ] || exit 21
echo 'first: ...and it finished as it should.' >&2
# no sense continuing the test; can't test anything if second already
# ran.
exit 0
fi
echo 'first: second has not started yet, good.' >&2
echo 'first spin' >&2
redo 1.a.spin
[ -e 1.a.spin ] || exit 11
echo 'first spin complete' >&2
! [ -e second.start ] || exit 22

View file

@ -0,0 +1,6 @@
# We should be running in parallel with a jobserver shared with second.do.
# Give second.do some time to start but not finish.
sleep 1
[ -e parallel2.start ] || exit 31
! [ -e parallel2.end ] || exit 32

View file

@ -0,0 +1,4 @@
rm -f $1.start $1.end
: >$1.start
sleep 2
: >$1.end

View file

@ -0,0 +1,7 @@
# Test that -j2 really gives us parallel builds with their own tokens.
# (It's hard to test for sure that we have our own tokens, but if we're
# sharing with other tests, we can't be sure that parallel2 will run while
# parallel is running, and the race condition will make this test at least
# be flakey instead of pass, which means there's a bug.)
rm -f *.sub *.spin *.x *.log parallel *.start *.end
redo parallel parallel2

View file

@ -0,0 +1,8 @@
rm -f $1.start $1.end
echo 'second start' >&2
: >$1.start
redo 2.x
echo 'second sleep' >&2
redo-ifchange first # wait until 'first' finishes, if it's running
echo 'second end' >&2
: >$1.end

View file

@ -0,0 +1,4 @@
# Test that -j1 really serializes all sub-redo processes.
rm -f *.sub *.spin *.x first second *.start *.end
redo first second

View file

@ -1,2 +1,3 @@
*.log
*.out *.out
whichmake whichmake

View file

@ -12,7 +12,12 @@ run() {
redo y redo y
rm -f *.out rm -f *.out
redo -j10 y # Capture output to y.log because we know this intentionally generates
# a scary-looking redo warning (overriding the jobserver).
if ! redo -j10 y 2>y.log; then
cat y.log
exit 99
fi
} }
run run

View file

@ -1 +1 @@
rm -f *~ .*~ *.out whichmake rm -f *~ .*~ *.out whichmake *.log