Debian Codegraph @

tests/functional/events/30-task-event-mail-2.t

raw
1 #!/usr/bin/env bash
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #-------------------------------------------------------------------------------
18 # Test event mail.
19 . "$(dirname "$0")/test_header"
20 if ! command -v mail 2>'/dev/null'; then
21 skip_all '"mail" command not available'
22 fi
23 set_test_number 15
24 mock_smtpd_init
25 OPT_SET=()
26 if [[ "${TEST_NAME_BASE}" == *-globalcfg ]]; then
27 create_test_global_config "" "
28 [scheduler]
29 [[mail]]
30 footer = see: http://localhost/stuff/%(owner)s/%(workflow)s/
31 smtp = ${TEST_SMTPD_HOST}
32 [task events]
33 mail events = failed, retry, succeeded
34 "
35 OPT_SET=(-s 'GLOBALCFG=True')
36 else
37 create_test_global_config "
38 [scheduler]
39 [[mail]]
40 smtp = ${TEST_SMTPD_HOST}
41 "
42 fi
43
44 install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"
45 run_ok "${TEST_NAME_BASE}-validate" \
46 cylc validate "${OPT_SET[@]}" "$WORKFLOW_NAME"
47 workflow_run_ok "${TEST_NAME_BASE}-run" \
48 cylc play --debug --no-detach "${OPT_SET[@]}" "$WORKFLOW_NAME"
49
50 # 1 - retry
51 for i in {1..5}; do
52 run_ok "${TEST_NAME_BASE}-t${i}-01" grep -Pizo "job: 1/t${i}/01.*\n.*event: retry" "$TEST_SMTPD_LOG"
53 done
54
55 # 2 - fail
56 for i in {1..5}; do
57 run_ok "${TEST_NAME_BASE}-t${i}-02" grep -Pizo "job: 1/t${i}/02.*\n.*event: failed" "$TEST_SMTPD_LOG"
58 done
59
60 contains_ok "${TEST_SMTPD_LOG}" <<__LOG__
61 see: http://localhost/stuff/${USER}/${WORKFLOW_NAME}/
62 __LOG__
63
64 run_ok "${TEST_NAME_BASE}-grep-log" \
65 grep -qPizo "Subject: \[. tasks retry\]\n? ${WORKFLOW_NAME}" "${TEST_SMTPD_LOG}"
66 run_ok "${TEST_NAME_BASE}-grep-log" \
67 grep -qPizo "Subject: \[. tasks failed\]\n? ${WORKFLOW_NAME}" "${TEST_SMTPD_LOG}"
68
69 purge
70 mock_smtpd_kill