#!/bin/bash
set -e
set -o pipefail
set -u

# This tests checks that the fd correctly handles the case where two different
# threads access the same plugin context at the same time.  This is done by
# canceling a job while the job is inside the plugin.

TestName="$(basename "$(pwd)")"
export TestName

JobName=cancel-check

#shellcheck source=../../environment.in
. ./environment

#shellcheck source=../../scripts/functions
. "${BAREOS_SCRIPTS_DIR}"/functions

start_test

logf="$tmp/cancel-check-no-wait.out"

cat <<END_OF_DATA >$tmp/bconcmds
@$out ${NULL_DEV}
messages
@$out $logf
run job=$JobName fileset=CancelNoWaitFileset yes
wait
messages
status client
END_OF_DATA

run_bconsole

expect_not_grep "Failed to connect to Client" \
  "$logf" \
  "The client crashed"

end_test
