Permalink
Browse files

Add a timemachine tool script

- Wrapper around faketime
- Provides an interface to run tests at specific points in time
  • Loading branch information...
lauft committed Jan 19, 2019
1 parent 42acf83 commit 68549dc22d5e18792b19397011e5f4f0b521837a
Showing with 46 additions and 0 deletions.
  1. +46 −0 test/timemachine
@@ -0,0 +1,46 @@
#!/bin/bash

# parse options/arguments
until [[ -z "${1}" ]] ; do
case "${1}" in
--minute)
shift
minutes="${minutes} ${1}"
;;
--hour)
shift
hours="${hours} ${1}"
;;
--day)
shift
days="${days} ${1}"
;;
--fail-at-end)
fail_at_end=1
;;
-*)
echo "Unknown option '${1}'"
exit 1
;;
*)
tests="${tests} ${1}"
;;
esac
shift
done

for day in ${days-$(date --rfc-3339=date)} ; do
for minute in ${minutes-$(echo "0$(rand -M 60)" | sed "s|.\+\(..\)\$|\1|g")} ; do
for hour in ${hours-$(seq -w 0 23)} ; do
date="${day}T${hour}:${minute}"
for single_test in ${tests} ; do
echo "Running test ${single_test} at ${date}"
faketime "@${date}" "${single_test}"
if [[ $? -ne 0 ]] ; then
echo "Test ${single_test} broke at ${date}!"
[[ ${fail_at_end-0} -ne 0 ]] || break 2
fi
done
done
done
done

0 comments on commit 68549dc

Please sign in to comment.