check_openfile check_cloud_hash check_bscan add_log_message compare_backup_content
check_tls_traces println add_virtual_changer check_events check_events_json
create_many_hardlinks check_dot_status parse_fuse_trace generate_random_seek
- check_storage_selection check_json get_perm check_protect
+ check_storage_selection check_json get_perm check_protect
+ get_running_jobs
);
}
close(FP);
}
+
+sub get_running_jobs
+{
+ my ($client, $status) = @_;
+ my $count = 0;
+ my $tempfile = "$tmp/running_jobs.$$";
+ eval 'use JSON qw/decode_json/;';
+ if ($@) {
+ print "INFO: JSON validation is disabled ERR=$@\n";
+ }
+ open(FP, "|$bin/bconsole -c $conf/bconsole.conf >$tempfile");
+ print FP ".api 2 api_opts=j\n";
+ print FP ".status dir running client=$client\n";
+ close(FP);
+ open(FP, $tempfile);
+ <FP>; # Connecting to Director 127.0.0.1:8101
+ <FP>; # 1000 OK: 10002 127.0.0.1-dir Version: 16.0.1 (03 February 2023)
+ <FP>; # Enter a period to cancel a command.
+ <FP>; # .api 2 api_opts=j
+ <FP>; # .status dir running client=127.0.0.1-fd
+ my $data = decode_json(<FP>);
+ close(FP);
+ if ($status) {
+ $count = scalar(grep { $_->{status} eq $status } @{ $data->{running} });
+ } else {
+ $count = scalar( @{ $data->{running} });
+ }
+ print "$count\n";
+}
+
1;
. scripts/functions
copy_test_confs
-rm -f bin/bacula-dir.conf
+rm -f $conf/bacula-dir.conf
rm -f ${cwd}/tmp/RUN*log
rm -f ${cwd}/tmp/RUN_FD_FAILED
touch ${cwd}/tmp/log1.out
-/bin/cp -f scripts/bacula-dir.conf.testrunscript bin/bacula-dir.conf
+cp -f scripts/bacula-dir.conf.testrunscript $conf/bacula-dir.conf
echo "${cwd}/build/po" >${cwd}/tmp/file-list
start_test
+cat <<EOF > $tmp/asleep.sh
+#!/bin/sh
+
+client=\$1
+job=\$2
+sleep 5
+nb=\`$bperl -e 'get_running_jobs("$HOST-fd", "R")'\`
+if [ "\$nb" -ge 1 ]; then
+ echo Found \$nb running jobs...
+ exit 1
+else
+ echo Found 0 job...
+ exit 0
+fi
+EOF
+
+chmod +x $tmp/asleep.sh
+
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
label volume=TestVolume001 pool=Scratch
-setdebug dir level=200
+setdebug dir level=200 tags=scheduler trace=1
@$out ${cwd}/tmp/RUN_FD_WARNING.log
run job=RUN_FD_WARNING yes
wait
run job=RUN_JOBDEFS yes
wait
messages
+@$out $tmp/RUN_WAITQ_ASLEEP.log
+run job=RUN_WAITQ_ASLEEP yes
+@sleep 1
+run job=RUN_WAITQ_ASLEEP yes
@sleep 1
+run job=RUN_WAITQ_ASLEEP yes
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+@sleep 2
+.status dir running
+wait
+messages
+.jlist jobid=8
+.jlist jobid=9
+.jlist jobid=10
quit
END_OF_DATA
then
[ "$debug" = 1 ] && echo RUN_FD_WARNING ok
else
- echo "RUN_FD_WARNING in error"
+ echo "RUN_FD_WARNING in error a=$a b=$b c=$c"
bstat=1
fi
rstat=1
fi
+grep '{' $tmp/RUN_WAITQ_ASLEEP.log | perl -MJSON -e '
+$j1 = decode_json(<>);
+$j2 = decode_json(<>);
+$j3 = decode_json(<>);
+
+@js = sort { $a->{data}->[0]->{starttime} cmp $b->{data}->[0]->{starttime} } ($j1, $j2, $j3);
+unless ($js[0]->{data}->[0]->{endtime} lt $js[1]->{data}->[0]->{starttime}) {
+ print "1 $js[0]->{data}->[0]->{endtime} lt $js[1]->{data}->[0]->{starttime}\n";
+ exit 1;
+}
+unless ($js[1]->{data}->[0]->{endtime} lt $js[2]->{data}->[0]->{starttime}) {
+ print "2 $js[1]->{data}->[0]->{endtime} lt $js[2]->{data}->[0]->{starttime}\n";
+ exit 1;
+}
+exit 0;
+'
+
+if [ $? -ne 0 ]; then
+ print_debug "ERROR: Incorrect job order reported in $tmp/RUN_WAITQ_ASLEEP.log"
+ estat=1
+fi
end_test