Skip to content

Commit 3a1cbaf

Browse files
committed
update azure batch tests
Signed-off-by: adamrtalbot <12817534+adamrtalbot@users.noreply.github.com>
1 parent 8fca02a commit 3a1cbaf

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchServiceTest.groovy

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,80 @@ class AzBatchServiceTest extends Specification {
739739
[managedIdentity: [clientId: 'client-123']] | 'client-123'
740740
}
741741

742+
def 'should create task for submit without container' () {
743+
given:
744+
Global.session = Mock(Session) { getConfig()>>[:] }
745+
and:
746+
def POOL_ID = 'my-pool'
747+
def SAS = '123'
748+
def CONFIG = [storage: [sasToken: SAS]]
749+
def exec = Mock(AzBatchExecutor) {getConfig() >> new AzConfig(CONFIG) }
750+
AzBatchService azure = Spy(new AzBatchService(exec))
751+
and:
752+
def TASK = Mock(TaskRun) {
753+
getHash() >> HashCode.fromInt(1)
754+
getContainer() >> null
755+
getConfig() >> Mock(TaskConfig)
756+
}
757+
and:
758+
def SPEC = new AzVmPoolSpec(poolId: POOL_ID, vmType: Mock(AzVmType), opts: new AzPoolOpts([:]))
759+
760+
when:
761+
def result = azure.createTask(POOL_ID, 'salmon', TASK)
762+
then:
763+
1 * azure.getPoolSpec(POOL_ID) >> SPEC
764+
1 * azure.computeSlots(TASK, SPEC) >> 4
765+
1 * azure.resourceFileUrls(TASK, SAS) >> []
766+
1 * azure.outputFileUrls(TASK, SAS) >> []
767+
and:
768+
result.id == 'nf-01000000'
769+
result.requiredSlots == 4
770+
and:
771+
result.commandLine == "sh -c 'bash .command.run 2>&1 | tee .command.log'"
772+
and:
773+
result.containerSettings == null
774+
}
775+
776+
def 'should create task for submit with container and fusion' () {
777+
given:
778+
def SAS = '1234567890' * 10
779+
def AZURE = [storage: [sasToken: SAS, accountName: 'my-account']]
780+
Global.session = Mock(Session) { getConfig()>>[fusion:[enabled:true], azure: AZURE] }
781+
def WORKDIR = FileSystemPathFactory.parse('az://foo/work/dir')
782+
and:
783+
def POOL_ID = 'my-pool'
784+
def exec = Mock(AzBatchExecutor) {getConfig() >> new AzConfig(AZURE) }
785+
AzBatchService azure = Spy(new AzBatchService(exec))
786+
and:
787+
def TASK = Mock(TaskRun) {
788+
getHash() >> HashCode.fromInt(1)
789+
getContainer() >> 'ubuntu:latest'
790+
getConfig() >> Mock(TaskConfig)
791+
getWorkDir() >> WORKDIR
792+
toTaskBean() >> Mock(TaskBean) {
793+
getWorkDir() >> WORKDIR
794+
getInputFiles() >> [:]
795+
}
796+
}
797+
and:
798+
def SPEC = new AzVmPoolSpec(poolId: POOL_ID, vmType: Mock(AzVmType), opts: new AzPoolOpts([:]))
799+
800+
when:
801+
def result = azure.createTask(POOL_ID, 'salmon', TASK)
802+
then:
803+
1 * azure.getPoolSpec(POOL_ID) >> SPEC
804+
1 * azure.computeSlots(TASK, SPEC) >> 1
805+
1 * azure.resourceFileUrls(TASK, SAS) >> []
806+
1 * azure.outputFileUrls(TASK, SAS) >> []
807+
and:
808+
result.id == 'nf-01000000'
809+
result.requiredSlots == 1
810+
and:
811+
result.commandLine == "/usr/bin/fusion bash /fusion/az/foo/work/dir/.command.run"
812+
and:
813+
result.containerSettings.imageName == 'ubuntu:latest'
814+
result.containerSettings.containerRunOptions.contains('--privileged')
815+
result.containerSettings.containerRunOptions.contains('-e FUSION_WORK=/fusion/az/foo/work/dir')
816+
}
817+
742818
}

plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchTaskHandlerTest.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ import spock.lang.Specification
1818
*/
1919
class AzBatchTaskHandlerTest extends Specification {
2020

21-
def 'should validate config' () {
21+
def 'should validate config with and without container' () {
2222
when:
23-
def task = Mock(TaskRun) { getName() >> 'foo'; }
23+
def task = Mock(TaskRun) { getName() >> 'foo' }
2424
and:
2525
new AzBatchTaskHandler(task: task)
2626
.validateConfiguration()
2727
then:
28-
def e = thrown(ProcessUnrecoverableException)
29-
e.message.startsWith('No container image specified for process foo')
30-
28+
noExceptionThrown()
3129

3230
when:
3331
task = Mock(TaskRun) { getName() >> 'foo'; getContainer() >> 'ubuntu' }

0 commit comments

Comments
 (0)