selftests: Make sure print queue is empty before printing_var_exp test ends
authorSamuel Cabrero <scabrero@samba.org>
Fri, 17 Feb 2023 16:22:39 +0000 (17:22 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 20 Feb 2023 22:58:44 +0000 (22:58 +0000)
Although "lpq cache time" is 0 in the test environment the
"print_queue_length()" function can still return cached results. This is
because the print_queue_length() function calls print_queue_update(),
which just sends MSG_PRINTER_UPDATE to the samba-bgqd daemon and returns
without waiting for the daemon to update it.

This behavior causes problems in the selftests between
samba3.blackbox.printing_var_exp and samba3.rpc.spoolss.printserver
because when the later enumerates the printers at different levels and
compares the results the number of jobs can differ depending if samba-bgqd
updates the cache in between print_queue_update() and
get_queue_status() in the print_queue_length() function:

  test: samba3.rpc.spoolss.printserver.printserver.enum_printers(nt4_dc)
  time: 2023-02-17 13:07:34.043842Z
  Testing EnumPrinters level 0
  Testing EnumPrinters level 1
  Testing EnumPrinters level 2
  Checking EnumPrinters level 0 printer print_var_exp (ref print_var_exp)
  time: 2023-02-17 13:07:34.285992Z
  failure: samba3.rpc.spoolss.printserver.printserver.enum_printers(nt4_dc) [
  Exception: Exception: ../../source4/torture/rpc/spoolss.c:1132: cur->info0.cjobs was 1 (0x1), expected 0 (0x0): invalid value

To fix it, make sure the queue is empty before printing_var_exp test
ends.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Mon Feb 20 22:58:44 UTC 2023 on atb-devel-224

source3/script/tests/test_printing_var_exp.sh

index 3a5925045d2da9bc28166c7e2aa4c49aab377d05..41dc1cc707c612095138371b9d4b3db67d90e782 100755 (executable)
@@ -20,6 +20,7 @@ incdir=$(dirname $0)/../../../testprogs/blackbox
 . $incdir/common_test_fns.inc
 
 smbclient="$BINDIR/smbclient"
+rpcclient="$BINDIR/rpcclient"
 
 test_var_expansion()
 {
@@ -54,8 +55,39 @@ test_var_expansion()
        return 0
 }
 
+test_empty_queue()
+{
+       # Try several times until the bgqd daemon updates the print queue status
+       tries="3"
+       for i in $(seq 1 $tries); do
+               echo "Try $i"
+               JOBS=$($rpcclient ncacn_np:$SERVER_IP \
+                       -U $DOMAIN/$USERNAME%$PASSWORD \
+                       -c "enumjobs print_var_exp 2")
+               if [ $? -ne 0 ]; then
+                       return 1
+               fi
+               if [[ -z $JOBS ]]; then
+                       return 0
+               fi
+               if [[ $i -gt $tries ]]; then
+                       echo "Print queue not empty after $tries seconds:"
+                       echo $JOBS
+                       echo "Queue must be empty before leaving this test or" \
+                            "following ones may fail."
+                       return 1
+               fi
+               sleep 1
+       done
+       return 0
+}
+
 testit "Test variable expansion for '%U', '%u' and '%D'" \
        test_var_expansion ||
        failed=$(expr $failed + 1)
 
+testit "Test queue is empty" \
+       test_empty_queue ||
+       failed=$(expr $failed + 1)
+
 exit $failed