Skip to content

Commit

Permalink
feat: add submit unit test and refactor code for it
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Herr <[email protected]>
  • Loading branch information
jherr-dev committed Jun 22, 2023
1 parent 0bdebed commit bc49aae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package nextflow.ga4gh.tes.executor

import nextflow.ga4gh.tes.client.model.TesFileType
import nextflow.processor.TaskBean

import static nextflow.processor.TaskStatus.COMPLETED
import static nextflow.processor.TaskStatus.RUNNING
Expand Down Expand Up @@ -53,7 +54,7 @@ class TesTaskHandler extends TaskHandler {

final List<TesState> STARTED_STATUSES = [TesState.INITIALIZING, TesState.RUNNING, TesState.PAUSED] + COMPLETE_STATUSES

final TesExecutor executor
private TesExecutor executor

private final Path exitFile

Expand All @@ -75,6 +76,9 @@ class TesTaskHandler extends TaskHandler {

private String requestId

/** only for testing purpose -- do not use */
protected TesTaskHandler() {}

TesTaskHandler(TaskRun task, TesExecutor executor) {
super(task)
this.executor = executor
Expand All @@ -90,6 +94,8 @@ class TesTaskHandler extends TaskHandler {
this.traceFile = task.workDir.resolve(TaskRun.CMD_TRACE)
}

protected String getRequestId() { requestId }

@Override
boolean checkIfRunning() {

Expand Down Expand Up @@ -149,7 +155,7 @@ class TesTaskHandler extends TaskHandler {

// create task wrapper
String remoteBinDir = executor.getRemoteBinDir()
final bash = new TesBashBuilder(task, remoteBinDir)
final bash = newTesBashBuilder(task, remoteBinDir)
bash.build()

final body = newTesTask()
Expand All @@ -160,7 +166,11 @@ class TesTaskHandler extends TaskHandler {
status = TaskStatus.SUBMITTED
}

protected final TesTask newTesTask() {
protected TesBashBuilder newTesBashBuilder(TaskRun task, String remoteBinDir) {
return new TesBashBuilder(task, remoteBinDir)
}

protected TesTask newTesTask() {
// the cmd list to launch it
def job = new ArrayList(BashWrapperBuilder.BASH) << wrapperFile.getName()
List cmd = ['/bin/bash','-c', job.join(' ') + " &> $TaskRun.CMD_LOG" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

package nextflow.ga4gh.tes.executor

import nextflow.ga4gh.tes.client.api.TaskServiceApi
import nextflow.ga4gh.tes.client.model.TesCreateTaskResponse
import nextflow.ga4gh.tes.client.model.TesTask
import nextflow.processor.TaskStatus

import java.nio.file.Path
import java.nio.file.Paths

import nextflow.processor.TaskConfig
Expand Down Expand Up @@ -49,5 +55,33 @@ class TesTaskHandlerTest extends Specification {

}

def 'should submit job' () {

given:
def executor = Mock(TesExecutor)
def task = Mock(TaskRun)
def bashBuilder = Mock(TesBashBuilder)
def client = Mock(TaskServiceApi)
def handler = Spy(TesTaskHandler)
handler.@client = client
handler.@executor = executor
handler.task = task

def req = Mock(TesTask)
def resp = Mock(TesCreateTaskResponse)

when:
handler.submit()
then:
1 * executor.getRemoteBinDir() >> Path.of("/work/bin")
1 * handler.newTesBashBuilder(task, "/work/bin") >> bashBuilder
1 * bashBuilder.build() >> null
1 * handler.newTesTask() >> req
1 * client.createTask(req) >> resp
1 * resp.getId() >> '12345'

handler.status == TaskStatus.SUBMITTED
handler.requestId == '12345'
}

}

0 comments on commit bc49aae

Please sign in to comment.