Skip to content

Commit 6989255

Browse files
committed
Fix all tests failing when one fails
1 parent eebd359 commit 6989255

3 files changed

Lines changed: 30 additions & 60 deletions

File tree

src/test/kotlin/eu/openanalytics/shinyproxyoperator/MainIntegrationTest.kt

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import eu.openanalytics.shinyproxyoperator.helpers.IntegrationTestBase
2727
import eu.openanalytics.shinyproxyoperator.helpers.ShinyProxyTestInstance
2828
import io.fabric8.kubernetes.api.model.IntOrString
2929
import io.fabric8.kubernetes.client.readiness.Readiness
30-
import kotlinx.coroutines.GlobalScope
3130
import kotlinx.coroutines.delay
3231
import kotlinx.coroutines.launch
3332
import kotlinx.coroutines.withTimeout
@@ -97,7 +96,7 @@ class MainIntegrationTest : IntegrationTestBase() {
9796

9897
assertTrue(checked) // actually checked that ingress wasn't created when the ReplicaSet wasn't ready yet
9998

100-
val job = GlobalScope.launch {
99+
scope.launch {
101100
// let the operator finish its business
102101
operator.run(resourceRetriever, shinyProxyLister)
103102
}
@@ -107,7 +106,6 @@ class MainIntegrationTest : IntegrationTestBase() {
107106

108107
// 5. assert correctness
109108
spTestInstance.assertInstanceIsCorrect()
110-
job.cancel()
111109
}
112110

113111
@Test
@@ -125,7 +123,7 @@ class MainIntegrationTest : IntegrationTestBase() {
125123

126124
val (resourceRetriever, shinyProxyLister) = operator.prepare()
127125
// 2. start the operator and let it do it's work
128-
val job = GlobalScope.launch {
126+
scope.launch {
129127
operator.run(resourceRetriever, shinyProxyLister)
130128
}
131129

@@ -134,7 +132,6 @@ class MainIntegrationTest : IntegrationTestBase() {
134132

135133
// 4. assert correctness
136134
spTestInstance.assertInstanceIsCorrect()
137-
job.cancel()
138135
}
139136

140137
@Test
@@ -153,7 +150,7 @@ class MainIntegrationTest : IntegrationTestBase() {
153150

154151
// 2. start the operator and let it do it's work
155152
val (resourceRetriever, shinyProxyLister) = operator.prepare()
156-
val job = GlobalScope.launch {
153+
scope.launch {
157154
operator.run(resourceRetriever, shinyProxyLister)
158155
}
159156

@@ -208,9 +205,6 @@ class MainIntegrationTest : IntegrationTestBase() {
208205
spTestInstance.waitForReconcileCycle()
209206
spTestInstance.assertInstanceIsCorrect()
210207
logger.info { "Reconciled after deleting Ingress" }
211-
212-
job.cancel()
213-
logger.info { "Operator stopped" }
214208
}
215209

216210
@Test
@@ -228,7 +222,7 @@ class MainIntegrationTest : IntegrationTestBase() {
228222

229223
// 2. start the operator and let it do it's work
230224
val (resourceRetriever, shinyProxyLister) = operator.prepare()
231-
val job = GlobalScope.launch {
225+
scope.launch {
232226
operator.run(resourceRetriever, shinyProxyLister)
233227
}
234228

@@ -237,8 +231,6 @@ class MainIntegrationTest : IntegrationTestBase() {
237231

238232
// assert that there are no ReplicaSets created
239233
assertEquals(0, stableClient.apps().replicaSets().list().items.size)
240-
241-
job.cancel()
242234
}
243235

244236
@Test
@@ -256,7 +248,7 @@ class MainIntegrationTest : IntegrationTestBase() {
256248

257249
// 2. start the operator and let it do it's work
258250
val (resourceRetriever, shinyProxyLister) = operator.prepare()
259-
val job = GlobalScope.launch {
251+
scope.launch {
260252
operator.run(resourceRetriever, shinyProxyLister)
261253
}
262254

@@ -310,8 +302,6 @@ class MainIntegrationTest : IntegrationTestBase() {
310302

311303
// check ingress
312304
spTestInstance.assertIngressIsCorrect(spTestInstance.retrieveInstance())
313-
314-
job.cancel()
315305
}
316306

317307
@Test
@@ -330,7 +320,7 @@ class MainIntegrationTest : IntegrationTestBase() {
330320

331321
// 2. start the operator and let it do it's work
332322
val (resourceRetriever, shinyProxyLister) = operator.prepare()
333-
val job = GlobalScope.launch {
323+
scope.launch {
334324
operator.run(resourceRetriever, shinyProxyLister)
335325
}
336326

@@ -368,8 +358,6 @@ class MainIntegrationTest : IntegrationTestBase() {
368358
assertThrows<IllegalStateException>("Instance not found") {
369359
spTestInstanceOriginal.retrieveInstance()
370360
}
371-
372-
job.cancel()
373361
}
374362

375363
@Test
@@ -388,7 +376,7 @@ class MainIntegrationTest : IntegrationTestBase() {
388376

389377
// 2. start the operator and let it do it's work
390378
val (resourceRetriever, shinyProxyLister) = operator.prepare()
391-
val job = GlobalScope.launch {
379+
scope.launch {
392380
operator.run(resourceRetriever, shinyProxyLister)
393381
}
394382

@@ -439,8 +427,6 @@ class MainIntegrationTest : IntegrationTestBase() {
439427

440428
// 13. assert app still exists
441429
assertEquals(1, getPodsForInstance(spTestInstanceOriginal.hash)?.items?.size)
442-
443-
job.cancel()
444430
}
445431

446432
@Test
@@ -458,7 +444,7 @@ class MainIntegrationTest : IntegrationTestBase() {
458444

459445
// 2. start the operator and let it do it's work
460446
val (resourceRetriever, shinyProxyLister) = operator.prepare()
461-
val job = GlobalScope.launch {
447+
scope.launch {
462448
operator.run(resourceRetriever, shinyProxyLister)
463449
}
464450

@@ -483,8 +469,6 @@ class MainIntegrationTest : IntegrationTestBase() {
483469

484470
// 7. assert correctness
485471
spTestInstance2.assertInstanceIsCorrect()
486-
487-
job.cancel()
488472
}
489473

490474
@Test
@@ -502,7 +486,7 @@ class MainIntegrationTest : IntegrationTestBase() {
502486

503487
// 2. start the operator and let it do it's work
504488
val (resourceRetriever, shinyProxyLister) = operator.prepare()
505-
val job = GlobalScope.launch {
489+
scope.launch {
506490
operator.run(resourceRetriever, shinyProxyLister)
507491
}
508492

@@ -516,8 +500,6 @@ class MainIntegrationTest : IntegrationTestBase() {
516500
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
517501
assertEquals(1, ingresses.size)
518502
assertTrue(ingresses.get(0).spec.rules.get(0).http.paths.get(0).path.endsWith("/"));
519-
520-
job.cancel()
521503
}
522504

523505

@@ -536,7 +518,7 @@ class MainIntegrationTest : IntegrationTestBase() {
536518

537519
// 2. start the operator and let it do it's work
538520
val (resourceRetriever, shinyProxyLister) = operator.prepare()
539-
val job = GlobalScope.launch {
521+
scope.launch {
540522
operator.run(resourceRetriever, shinyProxyLister)
541523
}
542524

@@ -551,8 +533,6 @@ class MainIntegrationTest : IntegrationTestBase() {
551533
val ingresses = namespacedClient.inNamespace(namespace).network().v1().ingresses().list().items
552534
assertEquals(1, ingresses.size)
553535
assertTrue(ingresses.get(0).spec.rules.get(0).http.paths.get(0).path.endsWith("/"));
554-
555-
job.cancel()
556536
}
557537

558538
/**
@@ -574,7 +554,7 @@ class MainIntegrationTest : IntegrationTestBase() {
574554

575555
// 2. start the operator and let it do it's work
576556
val (resourceRetriever, shinyProxyLister) = operator.prepare()
577-
val job = GlobalScope.launch {
557+
val job = scope.launch {
578558
operator.run(resourceRetriever, shinyProxyLister)
579559
}
580560

@@ -640,8 +620,6 @@ class MainIntegrationTest : IntegrationTestBase() {
640620
assertThrows<IllegalStateException>("Instance not found") {
641621
spTestInstanceOriginal.retrieveInstance()
642622
}
643-
644-
job.cancel()
645623
}
646624

647625
@Test
@@ -662,7 +640,7 @@ class MainIntegrationTest : IntegrationTestBase() {
662640
val (resourceRetriever, shinyProxyLister) = operator.prepare()
663641

664642
// 2. start the operator and let it do it's work
665-
val job = GlobalScope.launch {
643+
val job = scope.launch {
666644
operator.run(resourceRetriever, shinyProxyLister)
667645
}
668646

@@ -677,7 +655,7 @@ class MainIntegrationTest : IntegrationTestBase() {
677655
val instance = spTestInstance.retrieveInstance().status.instances.first()
678656

679657
// 5. schedule reconcile directly after deleting
680-
GlobalScope.launch {
658+
scope.launch {
681659
repeat(10) {
682660
delay(10)
683661
logger.debug { "Trying to trigger bug, by triggering reconcile with old status" }
@@ -717,7 +695,7 @@ class MainIntegrationTest : IntegrationTestBase() {
717695

718696
val (resourceRetriever, shinyProxyLister) = operator.prepare()
719697
// 2. start the operator and let it do it's work
720-
val job = GlobalScope.launch {
698+
scope.launch {
721699
operator.run(resourceRetriever, shinyProxyLister)
722700
}
723701

@@ -785,9 +763,6 @@ class MainIntegrationTest : IntegrationTestBase() {
785763

786764
// 13. assert instance A' is correct
787765
instanceAPrime.assertInstanceIsCorrect(1, true, 1)
788-
789-
job.cancel()
790-
791766
}
792767

793768
// see #25154
@@ -888,7 +863,7 @@ class MainIntegrationTest : IntegrationTestBase() {
888863
val (resourceRetriever, shinyProxyLister) = operator.prepare()
889864

890865
// 3. start the operator and let it do it's work
891-
val job = GlobalScope.launch {
866+
scope.launch {
892867
operator.run(resourceRetriever, shinyProxyLister)
893868
}
894869

@@ -897,7 +872,6 @@ class MainIntegrationTest : IntegrationTestBase() {
897872

898873
// 5. assert correctness
899874
spTestInstance.assertInstanceIsCorrect()
900-
job.cancel()
901875
}
902876

903877
@Test
@@ -916,7 +890,7 @@ class MainIntegrationTest : IntegrationTestBase() {
916890
val (resourceRetriever, shinyProxyLister) = operator.prepare()
917891

918892
// 3. start the operator and let it do it's work
919-
val job = GlobalScope.launch {
893+
scope.launch {
920894
operator.run(resourceRetriever, shinyProxyLister)
921895
}
922896

@@ -948,8 +922,6 @@ class MainIntegrationTest : IntegrationTestBase() {
948922
LabelFactory.INSTANCE_LABEL to spTestInstance.hash,
949923
LabelFactory.REVISION_LABEL to "0"
950924
), rule.podAffinityTerm.labelSelector.matchLabels)
951-
952-
job.cancel()
953925
}
954926

955927
@Test
@@ -968,7 +940,7 @@ class MainIntegrationTest : IntegrationTestBase() {
968940
val (resourceRetriever, shinyProxyLister) = operator.prepare()
969941

970942
// 3. start the operator and let it do it's work
971-
val job = GlobalScope.launch {
943+
scope.launch {
972944
operator.run(resourceRetriever, shinyProxyLister)
973945
}
974946

@@ -999,8 +971,6 @@ class MainIntegrationTest : IntegrationTestBase() {
999971
LabelFactory.INSTANCE_LABEL to spTestInstance.hash,
1000972
LabelFactory.REVISION_LABEL to "0"
1001973
), rule.labelSelector.matchLabels)
1002-
1003-
job.cancel()
1004974
}
1005975

1006976

@@ -1020,7 +990,7 @@ class MainIntegrationTest : IntegrationTestBase() {
1020990
val (resourceRetriever, shinyProxyLister) = operator.prepare()
1021991

1022992
// 3. start the operator and let it do it's work
1023-
val job = GlobalScope.launch {
993+
scope.launch {
1024994
operator.run(resourceRetriever, shinyProxyLister)
1025995
}
1026996

@@ -1052,8 +1022,6 @@ class MainIntegrationTest : IntegrationTestBase() {
10521022
LabelFactory.INSTANCE_LABEL to spTestInstance.hash,
10531023
LabelFactory.REVISION_LABEL to "0"
10541024
), rule.podAffinityTerm.labelSelector.matchLabels)
1055-
1056-
job.cancel()
10571025
}
10581026

10591027
@Test
@@ -1071,7 +1039,7 @@ class MainIntegrationTest : IntegrationTestBase() {
10711039

10721040
val (resourceRetriever, shinyProxyLister) = operator.prepare()
10731041
// 2. start the operator and let it do it's work
1074-
val job = GlobalScope.launch {
1042+
scope.launch {
10751043
operator.run(resourceRetriever, shinyProxyLister)
10761044
}
10771045

@@ -1126,8 +1094,6 @@ class MainIntegrationTest : IntegrationTestBase() {
11261094
assertEquals(sp.subPath, path2.path)
11271095
assertEquals("sp-${sp.metadata.name}-svc".take(63), path2.backend.service.name)
11281096
assertEquals(80, path2.backend.service.port.number)
1129-
1130-
job.cancel()
11311097
}
11321098

11331099
@Test
@@ -1145,7 +1111,7 @@ class MainIntegrationTest : IntegrationTestBase() {
11451111

11461112
val (resourceRetriever, shinyProxyLister) = operator.prepare()
11471113
// 2. start the operator and let it do it's work
1148-
val job = GlobalScope.launch {
1114+
scope.launch {
11491115
operator.run(resourceRetriever, shinyProxyLister)
11501116
}
11511117

@@ -1186,8 +1152,6 @@ class MainIntegrationTest : IntegrationTestBase() {
11861152
"nginx.ingress.kubernetes.io/ssl-redirect" to "true",
11871153
"nginx.ingress.kubernetes.io/proxy-body-size" to "300m"
11881154
), ingress.metadata.annotations)
1189-
1190-
job.cancel()
11911155
}
11921156

11931157
@Test
@@ -1205,7 +1169,7 @@ class MainIntegrationTest : IntegrationTestBase() {
12051169

12061170
val (resourceRetriever, shinyProxyLister) = operator.prepare()
12071171
// 2. start the operator and let it do it's work
1208-
val job = GlobalScope.launch {
1172+
scope.launch {
12091173
operator.run(resourceRetriever, shinyProxyLister)
12101174
}
12111175

@@ -1224,8 +1188,6 @@ class MainIntegrationTest : IntegrationTestBase() {
12241188
assertEquals(mapOf(
12251189
"my-service-ingress-patch" to "abc"
12261190
), service.metadata.annotations)
1227-
1228-
job.cancel()
12291191
}
12301192

12311193
}

src/test/kotlin/eu/openanalytics/shinyproxyoperator/helpers/IntegrationTestBase.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ import io.fabric8.kubernetes.client.KubernetesClientException
3535
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
3636
import io.fabric8.kubernetes.client.dsl.Resource
3737
import io.fabric8.kubernetes.client.dsl.RollableScalableResource
38+
import kotlinx.coroutines.CoroutineScope
39+
import kotlinx.coroutines.Dispatchers
3840
import kotlinx.coroutines.GlobalScope
3941
import kotlinx.coroutines.Job
42+
import kotlinx.coroutines.cancel
4043
import kotlinx.coroutines.delay
4144
import kotlinx.coroutines.launch
4245
import kotlinx.coroutines.runBlocking
@@ -59,9 +62,12 @@ abstract class IntegrationTestBase {
5962
createKubernetesClient()
6063
}
6164

65+
protected val scope = CoroutineScope(Dispatchers.Default)
66+
6267
@AfterEach
6368
fun cleanup() {
6469
runBlocking {
70+
scope.cancel()
6571
deleteNamespaces()
6672
stableClient.httpClient.close()
6773
}

0 commit comments

Comments
 (0)