From 1663096aff92ff43deca889d413a55db590f5f10 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 18 Jan 2023 18:57:28 +0100 Subject: [PATCH] regress: Tweak runscript-test --- .../scripts/bacula-dir.conf.testrunscript.in | 36 ++++++++++ regress/scripts/functions.pm | 33 ++++++++- regress/tests/runscript-test | 71 +++++++++++++++++-- 3 files changed, 135 insertions(+), 5 deletions(-) diff --git a/regress/scripts/bacula-dir.conf.testrunscript.in b/regress/scripts/bacula-dir.conf.testrunscript.in index a6c5e4024..b0fecdfc8 100644 --- a/regress/scripts/bacula-dir.conf.testrunscript.in +++ b/regress/scripts/bacula-dir.conf.testrunscript.in @@ -238,6 +238,42 @@ Job { } } +Job { + Name = "RUN_WAITQ_CMD" + FileSet = FS_TESTJOB + JobDefs = DefaultJob + Maximum Concurrent Jobs = 1 + RunScript { + RunsWhen = Queued + Command = "@tmpdir@/queue.sh %i" + failjobonerror = no + runsonclient = no + } + RunScript { + RunsWhen = After + Command = "sleep 5" + runsonclient = yes + } +} + +Job { + Name = "RUN_WAITQ_ASLEEP" + FileSet = FS_TESTJOB + JobDefs = DefaultJob + Maximum Concurrent Jobs = 10 + RunScript { + RunsWhen = Queued + Command = "@tmpdir@/asleep.sh %c %n" + failjobonerror = no + runsonclient = no + } + RunScript { + RunsWhen = After + Command = "sleep 15" + runsonclient = yes + } +} + Job { Name = "Restore" Type = Restore diff --git a/regress/scripts/functions.pm b/regress/scripts/functions.pm index 4849d39be..4a02a5fc4 100644 --- a/regress/scripts/functions.pm +++ b/regress/scripts/functions.pm @@ -52,7 +52,8 @@ our @EXPORT = qw(update_some_files create_many_files check_multiple_copies 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 ); @@ -2621,4 +2622,34 @@ sub check_protect } 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); + ; # Connecting to Director 127.0.0.1:8101 + ; # 1000 OK: 10002 127.0.0.1-dir Version: 16.0.1 (03 February 2023) + ; # Enter a period to cancel a command. + ; # .api 2 api_opts=j + ; # .status dir running client=127.0.0.1-fd + my $data = decode_json(); + close(FP); + if ($status) { + $count = scalar(grep { $_->{status} eq $status } @{ $data->{running} }); + } else { + $count = scalar( @{ $data->{running} }); + } + print "$count\n"; +} + 1; diff --git a/regress/tests/runscript-test b/regress/tests/runscript-test index 85da7dc40..68b48c0e2 100755 --- a/regress/tests/runscript-test +++ b/regress/tests/runscript-test @@ -12,22 +12,40 @@ JobName=backup . 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 < $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 <${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 @@ -62,7 +80,31 @@ st dir 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 @@ -160,7 +202,7 @@ if [ $a = 0 -a $b != 0 -a $c = 0 ] 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 @@ -180,5 +222,26 @@ else 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 -- 2.47.3