|
| 1 | +/* |
| 2 | + * Copyright (c) 2012, the authors. |
| 3 | + * |
| 4 | + * This file is part of 'Nextflow'. |
| 5 | + * |
| 6 | + * Nextflow is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * Nextflow is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with Nextflow. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package nextflow.executor |
| 21 | + |
| 22 | +import java.nio.file.Files |
| 23 | + |
| 24 | +import nextflow.processor.TaskConfig |
| 25 | +import nextflow.processor.TaskHandler |
| 26 | +import nextflow.processor.TaskRun |
| 27 | +import spock.lang.Specification |
| 28 | +/** |
| 29 | + * |
| 30 | + * @author Paolo Di Tommaso <paolo.ditommaso@gmail.com> |
| 31 | + */ |
| 32 | +class GridExecutorTest extends Specification { |
| 33 | + |
| 34 | + |
| 35 | + def testCheckIfNotRunning(){ |
| 36 | + |
| 37 | + setup: |
| 38 | + def task = Mock(TaskRun) |
| 39 | + def config = Mock(TaskConfig) |
| 40 | + def executor = Mock(AbstractGridExecutor) |
| 41 | + |
| 42 | + when: |
| 43 | + def handler = new GridTaskHandler(task, config, executor) |
| 44 | + handler.status = TaskHandler.Status.SUBMITTED |
| 45 | + then: |
| 46 | + !handler.checkIfRunning() |
| 47 | + handler.status == TaskHandler.Status.SUBMITTED |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + def testCheckIfRunning(){ |
| 52 | + |
| 53 | + setup: |
| 54 | + def task = Mock(TaskRun) |
| 55 | + task.getCmdStartedFile() >> Files.createTempFile('checkIfRun',null) |
| 56 | + |
| 57 | + def config = Mock(TaskConfig) |
| 58 | + def executor = Mock(AbstractGridExecutor) |
| 59 | + |
| 60 | + when: |
| 61 | + def handler = new GridTaskHandler(task, config, executor) |
| 62 | + handler.status = TaskHandler.Status.SUBMITTED |
| 63 | + then: |
| 64 | + handler.checkIfRunning() |
| 65 | + handler.status == TaskHandler.Status.RUNNING |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + def testCheckIfTerminated(){ |
| 72 | + |
| 73 | + setup: |
| 74 | + def task = Mock(TaskRun) |
| 75 | + def config = Mock(TaskConfig) |
| 76 | + def executor = Mock(AbstractGridExecutor) |
| 77 | + |
| 78 | + when: |
| 79 | + def handler = new GridTaskHandler(task, config, executor) |
| 80 | + handler.status = TaskHandler.Status.RUNNING |
| 81 | + then: |
| 82 | + !handler.checkIfCompleted() |
| 83 | + handler.status == TaskHandler.Status.RUNNING |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + def testCheckIfTerminatedTrue() { |
| 88 | + |
| 89 | + setup: |
| 90 | + def task = new TaskRun() |
| 91 | + task.workDirectory = Files.createTempDirectory('testHandler') |
| 92 | + |
| 93 | + def config = Mock(TaskConfig) |
| 94 | + def executor = Mock(AbstractGridExecutor) |
| 95 | + |
| 96 | + when: |
| 97 | + def handler = new GridTaskHandler(task, config, executor) |
| 98 | + handler.status = TaskHandler.Status.RUNNING |
| 99 | + handler.exitFile.text = '33' |
| 100 | + then: |
| 101 | + handler.checkIfCompleted() |
| 102 | + handler.status == TaskHandler.Status.COMPLETED |
| 103 | + handler.task.exitCode == 33 |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + def testCheckIfTerminateEmptyFile() { |
| 108 | + |
| 109 | + def task = new TaskRun() |
| 110 | + task.workDirectory = Files.createTempDirectory('testHandler') |
| 111 | + |
| 112 | + def config = Mock(TaskConfig) |
| 113 | + def executor = Mock(AbstractGridExecutor) |
| 114 | + |
| 115 | + when: |
| 116 | + def handler = new GridTaskHandler(task, config, executor) |
| 117 | + handler.status = TaskHandler.Status.RUNNING |
| 118 | + handler.exitFile.text = '' |
| 119 | + |
| 120 | + then: |
| 121 | + !handler.checkIfCompleted() |
| 122 | + sleep 5_100 |
| 123 | + handler.checkIfCompleted() |
| 124 | + handler.status == TaskHandler.Status.COMPLETED |
| 125 | + handler.task.exitCode == Integer.MAX_VALUE |
| 126 | + |
| 127 | + } |
| 128 | + |
| 129 | + |
| 130 | + def testCheckIfTerminateEmptyWithLatency() { |
| 131 | + |
| 132 | + def task = new TaskRun() |
| 133 | + task.workDirectory = Files.createTempDirectory('testHandler') |
| 134 | + def config = Mock(TaskConfig) |
| 135 | + def executor = Mock(AbstractGridExecutor) |
| 136 | + |
| 137 | + when: |
| 138 | + def handler = new GridTaskHandler(task, config, executor) |
| 139 | + handler.status = TaskHandler.Status.RUNNING |
| 140 | + handler.exitFile.text = '' |
| 141 | + |
| 142 | + assert handler.checkIfCompleted() == false |
| 143 | + sleep 500 |
| 144 | + handler.exitFile.text = '123' |
| 145 | + |
| 146 | + then: |
| 147 | + handler.checkIfCompleted() |
| 148 | + handler.status == TaskHandler.Status.COMPLETED |
| 149 | + handler.task.exitCode == 123 |
| 150 | + |
| 151 | + } |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +} |
0 commit comments