]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Tweak runscript-test
authorEric Bollengier <eric@baculasystems.com>
Wed, 18 Jan 2023 17:57:28 +0000 (18:57 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:01 +0000 (13:57 +0200)
regress/scripts/bacula-dir.conf.testrunscript.in
regress/scripts/functions.pm
regress/tests/runscript-test

index a6c5e402479c1880af2fc6881ad57fe9b933bd61..b0fecdfc80434dfb946882992f3b432bb13e8d8f 100644 (file)
@@ -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 
index 4849d39befef9ad3f0f909a6c4a409a2dae20bc5..4a02a5fc47e25e2240909b5905c032483a30282c 100644 (file)
@@ -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);
+    <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;
index 85da7dc4001e5ec963a53b7f38b6a9a53c99cfde..68b48c0e202feb5d13986ece1cacf5c7da0e642c 100755 (executable)
@@ -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 <<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
@@ -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