#!/bin/sh
#
# Run four jobs at the same time, with four Volumes, but set
#   Maximum Job Volumes = 1 on each of the Volumes.  Note,
#   Volume 2 will probably have two jobs on it.  Something to
#   be fixed in a later version.
#
TestName="maxuseduration-test"
JobName=maxuseduration
. scripts/functions

scripts/cleanup
scripts/copy-test-confs

change_jobname NightlySave $JobName

# 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 /dev/null
messages
@$out   ${cwd}/tmp/log1.out
label storage=File1 volume=TestVolume001
update Volume=TestVolume001
3
20
1
3
18
llist volume=TestVolume001
@#setdebug level=100 Storage=File1
run job=$JobName level=Full Storage=File1 yes
@sleep 30
update Volume=TestVolume001
1
1
18
mount storage=File1
wait
llist volume=TestVolume001
messages
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File1
stop_bareos

grep "Max configured use duration" ${cwd}/tmp/log1.out
if [ $? -eq 0 ] ; then
   echo "Error: max configured use duration exceeded"
   estat=1
fi
end_test
