1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-02 00:23:50 +03:00
Files
samba-mirror/source3/script/tests/test_printing_var_exp.sh
Samuel Cabrero 5c051eacd4 selftests: Make sure print queue is empty before printing_var_exp test ends
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
2023-02-20 22:58:44 +00:00

94 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
if [ $# -lt 4 ]; then
cat <<EOF
Usage: test_smbspool.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD
EOF
exit 1
fi
SERVER="$1"
SERVER_IP="$2"
DOMAIN="$3"
USERNAME="$4"
PASSWORD="$5"
shift 5
ADDARGS="$@"
incdir=$(dirname $0)/../../../testprogs/blackbox
. $incdir/subunit.sh
. $incdir/common_test_fns.inc
smbclient="$BINDIR/smbclient"
rpcclient="$BINDIR/rpcclient"
test_var_expansion()
{
logfile="${SELFTEST_TMPDIR}/${USER}_printing_var_exp.log"
$smbclient -U $DOMAIN/$USERNAME%$PASSWORD \
//$SERVER_IP/print_var_exp \
-c "print $SRCDIR/testdata/printing/example.ps"
if [ $? -ne 0 ]; then
rm -f "$logfile"
return 1
fi
cat "$logfile"
grep "Windows user: $USERNAME" "$logfile"
if [ $? -ne 0 ]; then
rm -f "$logfile"
return 1
fi
grep "UNIX user: $USERNAME" "$logfile"
if [ $? -ne 0 ]; then
rm -f "$logfile"
return 1
fi
grep "Domain: $DOMAIN" "$logfile"
if [ $? -ne 0 ]; then
rm -f "$logfile"
return 1
fi
rm -f "$logfile"
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