#!/bin/sh
#
#  Test MaxRunTime
#  Note: this test doesn't really do anything yet. It is used in helping
#    to duplicate bug #1268, but so far not successful ...
#

TestName="maxruntime-test"
JobName=backup

. scripts/functions

copy_test_confs

cp -f ${cwd}/scripts/bareos-dir.conf.maxruntime ${cwd}/bin/bareos-dir.conf
WHEN=`date '+%Y-%m-%d %H:%M:%S'`

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out ${cwd}/tmp/log1.out
messages
label volume=TestVolume001 pool=PoolA
label volume=TestVolume002 pool=Default
mount
wait
messages
setdebug level=60 dir
run job=RUN_MAXRUNTIME pool=PoolA yes
wait
messages
st dir
quit
END_OF_DATA

(mkfifo ${cwd}/tmp/fifo
 mkfifo ${cwd}/tmp/fifo2
 mkfifo ${cwd}/tmp/fifo3) 2> /dev/null

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

dstat=0
bstat=0
rstat=0
touch ${cwd}/tmp/log2.out

grep -e ': Fatal error: Max run time exceeded. Job canceled.' ${cwd}/tmp/log1.out >/dev/null
if [ $? -eq 0 ]
then
    [ "$debug" = 1 ] && echo MAXRUNTIME ok
else
   echo "MAXRUNTIME in error"
   bstat=1
fi

end_test
