#!/bin/sh -eu
# Targets must be built in parallel if “-j” option is given.

targets="a b c d e f g h "
num_targets=$(( ${#targets} / 2 ))

>all.do cat <<EOF
redo-ifchange ${targets}
EOF

>default.do cat <<EOF
redo-always
sleep 1
EOF

for jobs in 4 8; do
 timestamp_before=$(date +%s)
 redo -j "${jobs}"
 timestamp_after=$(date +%s)

 duration_observed=$(( ${timestamp_after} - ${timestamp_before} ))
 duration_expected=$(( ${num_targets} / ${jobs} + 1 ))

 test ${duration_observed} -le ${duration_expected}
done
