@@ -22,6 +22,7 @@ import io.seqera.sched.api.schema.v1a1.DiskAllocation
2222import io.seqera.sched.api.schema.v1a1.PriceModel as SchedPriceModel
2323import io.seqera.sched.api.schema.v1a1.ProvisioningModel
2424import nextflow.cloud.types.PriceModel
25+ import nextflow.fusion.FusionConfig
2526import nextflow.util.MemoryUnit
2627import spock.lang.Specification
2728
@@ -182,7 +183,8 @@ class MapperUtilTest extends Specification {
182183 def result = MapperUtil . toMachineRequirement(
183184 new MachineRequirementOpts ([arch : ' x86_64' ]),
184185 null ,
185- MemoryUnit . of(' 200 GB' )
186+ MemoryUnit . of(' 200 GB' ),
187+ false
186188 )
187189
188190 then :
@@ -193,7 +195,7 @@ class MapperUtilTest extends Specification {
193195
194196 def ' should return machine requirement with only disk' () {
195197 when :
196- def result = MapperUtil . toMachineRequirement(null , null , MemoryUnit . of(' 100 GB' ))
198+ def result = MapperUtil . toMachineRequirement(null , null , MemoryUnit . of(' 100 GB' ), false )
197199
198200 then :
199201 result != null
@@ -204,7 +206,7 @@ class MapperUtilTest extends Specification {
204206
205207 def ' should return null when no arch, no opts, and no disk' () {
206208 expect :
207- MapperUtil . toMachineRequirement(null , null , null ) == null
209+ MapperUtil . toMachineRequirement(null , null , null , false ) == null
208210 }
209211
210212 // tests for custom disk configuration options
@@ -295,7 +297,7 @@ class MapperUtilTest extends Specification {
295297 ])
296298
297299 when :
298- def result = MapperUtil . toMachineRequirement(opts, null , MemoryUnit . of(' 500 GB' ))
300+ def result = MapperUtil . toMachineRequirement(opts, null , MemoryUnit . of(' 500 GB' ), false )
299301
300302 then :
301303 result. arch == ' arm64'
@@ -367,7 +369,7 @@ class MapperUtilTest extends Specification {
367369 ])
368370
369371 when :
370- def result = MapperUtil . toMachineRequirement(opts, null , MemoryUnit . of(' 200 GB' ))
372+ def result = MapperUtil . toMachineRequirement(opts, null , MemoryUnit . of(' 200 GB' ), false )
371373
372374 then :
373375 result. arch == ' x86_64'
@@ -457,4 +459,51 @@ class MapperUtilTest extends Specification {
457459 e. message. contains(' diskEncrypted' )
458460 }
459461
462+ // tests for snapshot maxSpotAttempts defaulting
463+
464+ def ' should return machine requirement with only snapshot enabled' () {
465+ when :
466+ def result = MapperUtil . toMachineRequirement(null , null , null , true )
467+
468+ then :
469+ result != null
470+ result. snapshotEnabled == true
471+ result. maxSpotAttempts == FusionConfig . DEFAULT_SNAPSHOT_MAX_SPOT_ATTEMPTS
472+ }
473+
474+ def ' should use explicit maxSpotAttempts when snapshot enabled' () {
475+ when :
476+ def result = MapperUtil . toMachineRequirement(new MachineRequirementOpts ([maxSpotAttempts : 2 ]), null , null , true )
477+
478+ then :
479+ result. snapshotEnabled == true
480+ result. maxSpotAttempts == 2
481+ }
482+
483+ def ' should not default maxSpotAttempts when snapshot disabled' () {
484+ when :
485+ def result = MapperUtil . toMachineRequirement(new MachineRequirementOpts ([arch : ' x86_64' ]), null , null , false )
486+
487+ then :
488+ result. snapshotEnabled == null
489+ result. maxSpotAttempts == null
490+ }
491+
492+ def ' should combine snapshot with other machine requirement settings' () {
493+ when :
494+ def result = MapperUtil . toMachineRequirement(
495+ new MachineRequirementOpts ([arch : ' arm64' , provisioning : ' spot' ]),
496+ null ,
497+ MemoryUnit . of(' 100 GB' ),
498+ true
499+ )
500+
501+ then :
502+ result. arch == ' arm64'
503+ result. provisioning == ProvisioningModel . SPOT
504+ result. disk. sizeGiB == 100
505+ result. snapshotEnabled == true
506+ result. maxSpotAttempts == FusionConfig . DEFAULT_SNAPSHOT_MAX_SPOT_ATTEMPTS
507+ }
508+
460509}
0 commit comments