-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ac33e
commit d5b2db2
Showing
2 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/test/groovy/io/seqera/wave/service/blob/impl/KubeTransferStrategyTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Wave, containers provisioning service | ||
* Copyright (c) 2024, Seqera Labs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.seqera.wave.service.blob.impl | ||
|
||
import spock.lang.Specification | ||
|
||
import java.time.Duration | ||
|
||
import io.kubernetes.client.openapi.models.V1ContainerStateTerminated | ||
import io.kubernetes.client.openapi.models.V1Job | ||
import io.kubernetes.client.openapi.models.V1Pod | ||
import io.kubernetes.client.openapi.models.V1PodList | ||
import io.kubernetes.client.openapi.models.V1PodStatus | ||
import io.seqera.wave.configuration.BlobCacheConfig | ||
import io.seqera.wave.service.blob.BlobCacheInfo | ||
import io.seqera.wave.service.k8s.K8sService | ||
/** | ||
* | ||
* @author Munish Chouhan <[email protected]> | ||
*/ | ||
class KubeTransferStrategyTest extends Specification { | ||
|
||
def "transfer should return completed info when job is terminated"() { | ||
given: | ||
def config = Mock(BlobCacheConfig) { | ||
getTransferTimeout() >> Duration.ofSeconds(20) | ||
getBackoffLimit() >> 3 | ||
} | ||
|
||
List<String> command = ["command1", "command2"] | ||
String podName = "pod-123" | ||
def pod = new V1Pod(metadata: [name: podName]) | ||
pod.status = new V1PodStatus(phase: "Succeeded") | ||
def podList = new V1PodList(items: [pod]) | ||
String stdout = "success" | ||
|
||
def k8sService = Mock(K8sService) | ||
k8sService.transferJob(_, _, _, _) >> new V1Job(metadata: [name: "job-123"]) | ||
k8sService.waitJob(_, _) >> podList | ||
k8sService.getPod(_) >> pod | ||
k8sService.waitPod(_, _, _) >> new V1ContainerStateTerminated().exitCode(0) | ||
k8sService.logsPod(_, _) >> stdout | ||
|
||
KubeTransferStrategy strategy = new KubeTransferStrategy(blobConfig: config, k8sService: k8sService) | ||
BlobCacheInfo info = BlobCacheInfo.create("https://test.com/blobs", null) | ||
|
||
when: | ||
BlobCacheInfo result = strategy.transfer(info, command) | ||
|
||
then: | ||
result.exitStatus == 0 | ||
result.logs == stdout | ||
result.done() | ||
result.succeeded() | ||
} | ||
|
||
def "transfer should return failed info when job is not terminated"() { | ||
given: | ||
def config = Mock(BlobCacheConfig) { | ||
getTransferTimeout() >> Duration.ofSeconds(20) | ||
getBackoffLimit() >> 3 | ||
} | ||
|
||
List<String> command = ["command1", "command2"] | ||
String podName = "pod-123" | ||
def pod = new V1Pod(metadata: [name: podName]) | ||
pod.status = new V1PodStatus(phase: "Succeeded") | ||
def podList = new V1PodList(items: [pod]) | ||
String stdout = "failed" | ||
|
||
def k8sService = Mock(K8sService) | ||
k8sService.transferJob(_, _, _, _) >> new V1Job(metadata: [name: "job-123"]) | ||
k8sService.waitJob(_, _) >> podList | ||
k8sService.getPod(_) >> pod | ||
k8sService.waitPod(_, _, _) >> new V1ContainerStateTerminated().exitCode(1) | ||
k8sService.logsPod(_, _) >> stdout | ||
|
||
KubeTransferStrategy strategy = new KubeTransferStrategy(blobConfig: config, k8sService: k8sService) | ||
BlobCacheInfo info = BlobCacheInfo.create("https://test.com/blobs", null) | ||
|
||
when: | ||
BlobCacheInfo result = strategy.transfer(info, command) | ||
|
||
then: | ||
result.exitStatus == 1 | ||
result.logs == stdout | ||
result.done() | ||
!result.succeeded() | ||
} | ||
} |