Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Dec 10, 2013
1 parent db5be81 commit 2554316
Showing 1 changed file with 155 additions and 0 deletions.
155 changes: 155 additions & 0 deletions src/test/groovy/nextflow/executor/GridExecutorTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) 2012, the authors.
*
* This file is part of 'Nextflow'.
*
* Nextflow 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.
*
* Nextflow 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 Nextflow. If not, see <http://www.gnu.org/licenses/>.
*/

package nextflow.executor

import java.nio.file.Files

import nextflow.processor.TaskConfig
import nextflow.processor.TaskHandler
import nextflow.processor.TaskRun
import spock.lang.Specification
/**
*
* @author Paolo Di Tommaso <[email protected]>
*/
class GridExecutorTest extends Specification {


def testCheckIfNotRunning(){

setup:
def task = Mock(TaskRun)
def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.SUBMITTED
then:
!handler.checkIfRunning()
handler.status == TaskHandler.Status.SUBMITTED

}

def testCheckIfRunning(){

setup:
def task = Mock(TaskRun)
task.getCmdStartedFile() >> Files.createTempFile('checkIfRun',null)

def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.SUBMITTED
then:
handler.checkIfRunning()
handler.status == TaskHandler.Status.RUNNING

}



def testCheckIfTerminated(){

setup:
def task = Mock(TaskRun)
def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.RUNNING
then:
!handler.checkIfCompleted()
handler.status == TaskHandler.Status.RUNNING

}

def testCheckIfTerminatedTrue() {

setup:
def task = new TaskRun()
task.workDirectory = Files.createTempDirectory('testHandler')

def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.RUNNING
handler.exitFile.text = '33'
then:
handler.checkIfCompleted()
handler.status == TaskHandler.Status.COMPLETED
handler.task.exitCode == 33

}

def testCheckIfTerminateEmptyFile() {

def task = new TaskRun()
task.workDirectory = Files.createTempDirectory('testHandler')

def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.RUNNING
handler.exitFile.text = ''

then:
!handler.checkIfCompleted()
sleep 5_100
handler.checkIfCompleted()
handler.status == TaskHandler.Status.COMPLETED
handler.task.exitCode == Integer.MAX_VALUE

}


def testCheckIfTerminateEmptyWithLatency() {

def task = new TaskRun()
task.workDirectory = Files.createTempDirectory('testHandler')
def config = Mock(TaskConfig)
def executor = Mock(AbstractGridExecutor)

when:
def handler = new GridTaskHandler(task, config, executor)
handler.status = TaskHandler.Status.RUNNING
handler.exitFile.text = ''

assert handler.checkIfCompleted() == false
sleep 500
handler.exitFile.text = '123'

then:
handler.checkIfCompleted()
handler.status == TaskHandler.Status.COMPLETED
handler.task.exitCode == 123

}



}

0 comments on commit 2554316

Please sign in to comment.