From 59ce9cd550587287a32c6b5f9d71e4131da8eb9e Mon Sep 17 00:00:00 2001 From: Matt Shin Date: Tue, 28 Mar 2017 08:52:27 +0100 Subject: [PATCH] job.sh: fix ERR trap in semicolon commands Turn on `set -e` so that if `cmd1` fails in a `cmd1; cmd2` syntax, the failure is trapped. --- lib/cylc/job.sh | 3 +- .../03-get-graph-raw-4/suite.rc | 1 + tests/job-file-trap/02-pipefail.t | 1 - tests/jobscript/12-err-script.t | 2 +- tests/jobscript/15-semicolon.t | 28 +++++++++++++++++++ tests/jobscript/15-semicolon/reference.log | 4 +++ tests/jobscript/15-semicolon/suite.rc | 17 +++++++++++ 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100755 tests/jobscript/15-semicolon.t create mode 100644 tests/jobscript/15-semicolon/reference.log create mode 100644 tests/jobscript/15-semicolon/suite.rc diff --git a/lib/cylc/job.sh b/lib/cylc/job.sh index 7aa4ed848b2..4fb6e7670ee 100644 --- a/lib/cylc/job.sh +++ b/lib/cylc/job.sh @@ -53,8 +53,7 @@ cylc__job__main() { for signal_name in ${CYLC_VACATION_SIGNALS:-}; do trap "cylc__job__trap_vacation ${signal_name}" "${signal_name}" done - set -u - set -o pipefail + set -euo pipefail # Export CYLC_ suite and task environment variables cylc__job__inst__cylc_env # Write task job self-identify diff --git a/tests/api-suite-info/03-get-graph-raw-4/suite.rc b/tests/api-suite-info/03-get-graph-raw-4/suite.rc index 6299cff0a9e..b4a24a10eda 100644 --- a/tests/api-suite-info/03-get-graph-raw-4/suite.rc +++ b/tests/api-suite-info/03-get-graph-raw-4/suite.rc @@ -1,4 +1,5 @@ [cylc] + UTC mode = True [[reference test]] required run mode = live live mode suite timeout = PT30S diff --git a/tests/job-file-trap/02-pipefail.t b/tests/job-file-trap/02-pipefail.t index 421f02f5db7..209e9a1e461 100755 --- a/tests/job-file-trap/02-pipefail.t +++ b/tests/job-file-trap/02-pipefail.t @@ -30,7 +30,6 @@ suite_run_fail "${TEST_NAME_BASE}-run" \ T1_STATUS_FILE="${SUITE_RUN_DIR}/log/job/1/t1/01/job.status" contains_ok "${T1_STATUS_FILE}" <<'__STATUS__' CYLC_JOB_EXIT=EXIT -CYLC_JOB_EXIT=ERR __STATUS__ purge_suite "${SUITE_NAME}" diff --git a/tests/jobscript/12-err-script.t b/tests/jobscript/12-err-script.t index 5823da23e1a..b7391b24f66 100755 --- a/tests/jobscript/12-err-script.t +++ b/tests/jobscript/12-err-script.t @@ -22,7 +22,7 @@ set_test_number 4 install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" run_ok "${TEST_NAME_BASE}-validate" cylc validate "${SUITE_NAME}" run_ok "${TEST_NAME_BASE}-run" cylc run "${SUITE_NAME}" --reference-test --debug -grep_ok 'ERR foo bar baz qux' "${SUITE_RUN_DIR}/log/job/1/foo/01/job.err" +grep_ok 'EXIT foo bar baz qux' "${SUITE_RUN_DIR}/log/job/1/foo/01/job.err" run_fail "${TEST_NAME_BASE}-grep-02" \ grep -q -F 'ERR foo bar baz qux' "${SUITE_RUN_DIR}/log/job/1/foo/02/job.err" diff --git a/tests/jobscript/15-semicolon.t b/tests/jobscript/15-semicolon.t new file mode 100755 index 00000000000..ab3aa2b0ebd --- /dev/null +++ b/tests/jobscript/15-semicolon.t @@ -0,0 +1,28 @@ +#!/bin/bash +# THIS FILE IS PART OF THE CYLC SUITE ENGINE. +# Copyright (C) 2008-2017 NIWA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#------------------------------------------------------------------------------- +# Test error trapping in cmd1; cmd2 syntax. If cmd1 fails, the error trap +# should trigger. +. "$(dirname "${0}")/test_header" +set_test_number 2 + +install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" +run_ok "${TEST_NAME_BASE}-validate" cylc validate "${SUITE_NAME}" +run_ok "${TEST_NAME_BASE}-run" cylc run "${SUITE_NAME}" --reference-test --debug + +purge_suite "${SUITE_NAME}" +exit diff --git a/tests/jobscript/15-semicolon/reference.log b/tests/jobscript/15-semicolon/reference.log new file mode 100644 index 00000000000..90cba277933 --- /dev/null +++ b/tests/jobscript/15-semicolon/reference.log @@ -0,0 +1,4 @@ +2017-02-09T16:45:37Z INFO - Initial point: 1 +2017-02-09T16:45:37Z INFO - Final point: 1 +2017-02-09T16:45:37Z INFO - [foo.1] -triggered off [] +2017-02-09T16:45:37Z INFO - [foo.1] -triggered off [] diff --git a/tests/jobscript/15-semicolon/suite.rc b/tests/jobscript/15-semicolon/suite.rc new file mode 100644 index 00000000000..20c5fdb13ee --- /dev/null +++ b/tests/jobscript/15-semicolon/suite.rc @@ -0,0 +1,17 @@ +[cylc] + [[reference test]] + expected task failures = foo.1 + [[events]] + abort on stalled = True +[scheduling] + [[dependencies]] + graph = foo +[runtime] + [[foo]] + script = """ +if ((${CYLC_TASK_SUBMIT_NUMBER} == 1)); then + false; true +fi +""" + [[[job]]] + execution retry delays = PT0S