|
| 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 `cylc play` start up or resume under various contact scenarios: |
| 19 | +# - running, normally |
| 20 | +# - stopped, normally |
| 21 | +# - stopped, but orphaned contact file |
| 22 | +# - running, but can't be contacted |
| 23 | + |
| 24 | +. "$(dirname "$0")/test_header" |
| 25 | + |
| 26 | +set_test_number 10 |
| 27 | + |
| 28 | +init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__' |
| 29 | +[scheduling] |
| 30 | + [[graph]] |
| 31 | + R1 = foo |
| 32 | +[runtime] |
| 33 | + [[foo]] |
| 34 | + script = false |
| 35 | +__FLOW_CONFIG__ |
| 36 | + |
| 37 | +run_ok "${TEST_NAME_BASE}-validate" \ |
| 38 | + cylc validate "${WORKFLOW_NAME}" |
| 39 | + |
| 40 | +# Not running: play should start it up. |
| 41 | +# (run like this "(cmd &) >/dev/null" to discard the process killed message) |
| 42 | +(cylc play --pause --no-detach "${WORKFLOW_NAME}" \ |
| 43 | + 1>"${TEST_NAME_BASE}.out" 2>&1 &) 2>/dev/null |
| 44 | +poll_workflow_running |
| 45 | +poll_grep_workflow_log "Pausing the workflow: Paused on start up" |
| 46 | + |
| 47 | +# Already running: play should resume. |
| 48 | +TEST_NAME="${TEST_NAME_BASE}-resume" |
| 49 | +run_ok "${TEST_NAME}" \ |
| 50 | + cylc play "${WORKFLOW_NAME}" |
| 51 | + |
| 52 | +grep_ok "Resuming already-running workflow" "${TEST_NAME}.stdout" |
| 53 | +poll_grep_workflow_log "RESUMING the workflow now" |
| 54 | + |
| 55 | +# Orphan the contact file |
| 56 | +# Play should timeout, remove the contact file, and start up. |
| 57 | +TEST_NAME="${TEST_NAME_BASE}-orphan" |
| 58 | + |
| 59 | +eval "$(cylc get-workflow-contact "${WORKFLOW_NAME}" | grep CYLC_WORKFLOW_PID)" |
| 60 | +kill -9 "${CYLC_WORKFLOW_PID}" > /dev/null 2>&1 |
| 61 | + |
| 62 | +run_ok "${TEST_NAME}" \ |
| 63 | + cylc play "${WORKFLOW_NAME}" --comms-timeout=1 --pause |
| 64 | +grep_ok "Connection timed out (1000.0 ms)" "${TEST_NAME}.stderr" |
| 65 | +grep_ok "Removed contact file" "${TEST_NAME}.stderr" |
| 66 | +poll_grep_workflow_log "Pausing the workflow: Paused on start up" |
| 67 | + |
| 68 | +# Mess with the port: play aborts as can't tell if workflow is running or not. |
| 69 | +# (The ping times out, then `cylc psutil` can't find the workflow). |
| 70 | +eval "$(cylc get-workflow-contact "${WORKFLOW_NAME}" | grep CYLC_WORKFLOW_PORT)" |
| 71 | +sed -i 's/CYLC_WORKFLOW_PORT=.*/CYLC_WORKFLOW_PORT=490001/' \ |
| 72 | + "$WORKFLOW_RUN_DIR/.service/contact" |
| 73 | +run_fail "${TEST_NAME}" \ |
| 74 | + cylc play "${WORKFLOW_NAME}" --comms-timeout=1 |
| 75 | +grep_ok "Connection timed out (1000.0 ms)" "${TEST_NAME}.stderr" |
| 76 | +grep_ok "Cannot tell if the workflow is running" "${TEST_NAME}.stderr" |
| 77 | + |
| 78 | +# Restore contact file and shut down. |
| 79 | +sed -i "s/CYLC_WORKFLOW_PORT=.*/CYLC_WORKFLOW_PORT=${CYLC_WORKFLOW_PORT}/" \ |
| 80 | + "$WORKFLOW_RUN_DIR/.service/contact" |
| 81 | +run_ok "${TEST_NAME}" \ |
| 82 | + cylc stop --now "${WORKFLOW_NAME}" |
| 83 | + |
| 84 | +purge |
0 commit comments