Skip to content

Commit 35fcf56

Browse files
committed
Fix: K8sJob testing activepods instead of completiontime for completed()
Also, selectors and queries for tier=backend would pick up MySQL pods from other tests. Updated annotation as "compute" instead of "backend" to keep this test separate.
1 parent ae6006a commit 35fcf56

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/Kinds/K8sJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@ public function getDurationInSeconds(): int
151151
*/
152152
public function hasCompleted(): bool
153153
{
154-
return $this->getActivePodsCount() === 0;
154+
return !is_null($this->getCompletionTime());
155155
}
156156
}

tests/JobTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function test_job_build()
2525

2626
$job = $this->cluster->job()
2727
->setName('pi')
28-
->setLabels(['tier' => 'backend'])
28+
->setLabels(['tier' => 'compute'])
2929
->setAnnotations(['perl/annotation' => 'yes'])
3030
->setTTL(3600)
3131
->setTemplate($pod);
3232

3333
$this->assertEquals('batch/v1', $job->getApiVersion());
3434
$this->assertEquals('pi', $job->getName());
35-
$this->assertEquals(['tier' => 'backend'], $job->getLabels());
35+
$this->assertEquals(['tier' => 'compute'], $job->getLabels());
3636
$this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations());
3737
$this->assertEquals($pod->getName(), $job->getTemplate()->getName());
3838
$this->assertEquals('Never', $pod->getRestartPolicy());
@@ -57,7 +57,7 @@ public function test_job_from_yaml()
5757

5858
$this->assertEquals('batch/v1', $job->getApiVersion());
5959
$this->assertEquals('pi', $job->getName());
60-
$this->assertEquals(['tier' => 'backend'], $job->getLabels());
60+
$this->assertEquals(['tier' => 'compute'], $job->getLabels());
6161
$this->assertEquals(['perl/annotation' => 'yes'], $job->getAnnotations());
6262
$this->assertEquals($pod->getName(), $job->getTemplate()->getName());
6363
$this->assertEquals('Never', $pod->getRestartPolicy());
@@ -85,13 +85,13 @@ public function runCreationTests()
8585

8686
$pod = $this->cluster->pod()
8787
->setName('perl')
88-
->setLabels(['tier' => 'backend'])
88+
->setLabels(['tier' => 'compute'])
8989
->setContainers([$pi])
9090
->neverRestart();
9191

9292
$job = $this->cluster->job()
9393
->setName('pi')
94-
->setLabels(['tier' => 'backend'])
94+
->setLabels(['tier' => 'compute'])
9595
->setAnnotations(['perl/annotation' => 'yes'])
9696
->setTTL(3600)
9797
->setTemplate($pod);
@@ -108,7 +108,7 @@ public function runCreationTests()
108108

109109
$this->assertEquals('batch/v1', $job->getApiVersion());
110110
$this->assertEquals('pi', $job->getName());
111-
$this->assertEquals(['tier' => 'backend'], $job->getLabels());
111+
$this->assertEquals(['tier' => 'compute'], $job->getLabels());
112112

113113
$annotations = $job->getAnnotations();
114114
foreach (['perl/annotation' => 'yes'] as $key => $value) {
@@ -130,8 +130,7 @@ public function runCreationTests()
130130

131131
K8sJob::selectPods(function ($job) {
132132
$this->assertInstanceOf(K8sJob::class, $job);
133-
134-
return ['tier' => 'backend'];
133+
return ['tier' => 'compute'];
135134
});
136135

137136
$pods = $job->getPods();
@@ -149,7 +148,7 @@ public function runCreationTests()
149148
$job->refresh();
150149

151150
while (! $completionTime = $job->getCompletionTime()) {
152-
dump("Waiting for the competion time report of {$job->getName()}...");
151+
dump("Waiting for the completion time report of {$job->getName()}...");
153152
sleep(1);
154153
$job->refresh();
155154
}
@@ -185,7 +184,7 @@ public function runGetTests()
185184

186185
$this->assertEquals('batch/v1', $job->getApiVersion());
187186
$this->assertEquals('pi', $job->getName());
188-
$this->assertEquals(['tier' => 'backend'], $job->getLabels());
187+
$this->assertEquals(['tier' => 'compute'], $job->getLabels());
189188

190189
$annotations = $job->getAnnotations();
191190
foreach (['perl/annotation' => 'yes'] as $key => $value) {
@@ -210,7 +209,7 @@ public function runUpdateTests()
210209

211210
$this->assertEquals('batch/v1', $job->getApiVersion());
212211
$this->assertEquals('pi', $job->getName());
213-
$this->assertEquals(['tier' => 'backend'], $job->getLabels());
212+
$this->assertEquals(['tier' => 'compute'], $job->getLabels());
214213

215214
$this->assertInstanceOf(K8sPod::class, $job->getTemplate());
216215
}

tests/yaml/job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Job
33
metadata:
44
name: pi
55
labels:
6-
tier: backend
6+
tier: compute
77
annotations:
88
perl/annotation: "yes"
99
spec:

0 commit comments

Comments
 (0)