@@ -165,19 +165,26 @@ class MainIntegrationTest : IntegrationTestBase() {
165165 spTestInstance.assertInstanceIsCorrect()
166166
167167 // 5. Delete Replicaset -> reconcile -> assert it is still ok
168+ val replicaSetName = " sp-${sp.metadata.name} -rs-0-${spTestInstance.hash} " .take(63 )
168169 executeAsyncAfter100ms {
169- stableClient.apps().replicaSets()
170- .withName(" sp-${sp.metadata.name} -rs-${spTestInstance.hash} " .take(63 )).delete()
170+ getAndDelete(stableClient.apps().replicaSets().withName(replicaSetName))
171171 logger.info { " Deleted ReplicaSet" }
172172 }
173173 spTestInstance.waitForReconcileCycle()
174174 logger.info { " Reconciled after deleting RS" }
175+ // wait for replicaset to be ready
176+ withTimeout(50_000 ) {
177+ while (stableClient.apps().replicaSets().withName(replicaSetName)?.get()?.status?.readyReplicas != 1 ){
178+ logger.info { " Replicaset not yet ready" }
179+ delay(1000 )
180+ }
181+ }
182+ logger.info { " Replicaset ready" }
175183 spTestInstance.assertInstanceIsCorrect()
176184
177185 // 6. Delete ConfigMap -> reconcile -> assert it is still ok
178186 executeAsyncAfter100ms {
179- stableClient.configMaps().withName(" sp-${sp.metadata.name} -cm-${spTestInstance.hash} " .take(63 ))
180- .delete()
187+ getAndDelete(stableClient.configMaps().withName(" sp-${sp.metadata.name} -cm-${spTestInstance.hash} " .take(63 )))
181188 logger.info { " Deleted ConfigMap" }
182189 }
183190 spTestInstance.waitForOneReconcile()
@@ -186,8 +193,7 @@ class MainIntegrationTest : IntegrationTestBase() {
186193
187194 // 7. Delete Service -> reconcile -> assert it is still ok
188195 executeAsyncAfter100ms {
189- stableClient.services().withName(" sp-${sp.metadata.name} -svc" .take(63 ))
190- .delete()
196+ getAndDelete(stableClient.services().withName(" sp-${sp.metadata.name} -svc" .take(63 )))
191197 logger.info { " Deleted Service" }
192198 }
193199 spTestInstance.waitForOneReconcile()
@@ -196,8 +202,7 @@ class MainIntegrationTest : IntegrationTestBase() {
196202
197203 // 8. Delete Ingress -> reconcile -> assert it is still ok
198204 executeAsyncAfter100ms {
199- stableClient.network().v1().ingresses()
200- .withName(" sp-${sp.metadata.name} -ing" .take(63 )).delete()
205+ getAndDelete(stableClient.network().v1().ingresses().withName(" sp-${sp.metadata.name} -ing" .take(63 )))
201206 logger.info { " Deleted Ingress" }
202207 }
203208 spTestInstance.waitForReconcileCycle()
@@ -354,12 +359,7 @@ class MainIntegrationTest : IntegrationTestBase() {
354359 recyclableChecker.isRecyclable = true
355360
356361 // 8. wait for delete to happen
357- while (stableClient.pods().withName(" sp-${sp.metadata.name} -pod-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
358- || stableClient.configMaps().withName(" sp-${sp.metadata.name} -cm-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
359- || stableClient.services().withName(" sp-${sp.metadata.name} -svc-${spTestInstanceOriginal.hash} " .take(63 )).get() != null ) {
360- delay(1000 )
361- logger.debug { " Pod still exists!" }
362- }
362+ spTestInstanceOriginal.waitForDeletion(sp)
363363
364364 // 9. assert correctness
365365 spTestInstanceUpdated.assertInstanceIsCorrect()
@@ -427,12 +427,7 @@ class MainIntegrationTest : IntegrationTestBase() {
427427 recyclableChecker.isRecyclable = true
428428
429429 // 10. wait for delete to happen
430- while (stableClient.pods().withName(" sp-${sp.metadata.name} -pod-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
431- || stableClient.configMaps().withName(" sp-${sp.metadata.name} -cm-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
432- || stableClient.services().withName(" sp-${sp.metadata.name} -svc-${spTestInstanceOriginal.hash} " .take(63 )).get() != null ) {
433- delay(1000 )
434- logger.debug { " Pod still exists!" }
435- }
430+ spTestInstanceOriginal.waitForDeletion(sp)
436431
437432 // 11. assert older instance does not exist anymore
438433 assertThrows<IllegalStateException >(" Instance not found" ) {
@@ -636,12 +631,7 @@ class MainIntegrationTest : IntegrationTestBase() {
636631 spTestInstanceUpdated.waitForOneReconcile()
637632
638633 // 7. wait for delete to happen
639- while (stableClient.pods().withName(" sp-${sp.metadata.name} -pod-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
640- || stableClient.configMaps().withName(" sp-${sp.metadata.name} -cm-${spTestInstanceOriginal.hash} " .take(63 )).get() != null
641- || stableClient.services().withName(" sp-${sp.metadata.name} -svc-${spTestInstanceOriginal.hash} " .take(63 )).get() != null ) {
642- delay(1000 )
643- logger.debug { " Pod still exists!" }
644- }
634+ spTestInstanceOriginal.waitForDeletion(sp)
645635
646636 // 8. assert correctness
647637 spTestInstanceUpdated.assertInstanceIsCorrect()
@@ -712,8 +702,8 @@ class MainIntegrationTest : IntegrationTestBase() {
712702
713703 @Test
714704 fun `restore old config version` () =
715- // idea of test: launch instance A, update config to get instance B, and the update config again
716- // using the same config as A, resulting in instance A' (which is the same instance as A, as A was never removed!)
705+ // idea of test: launch instance A, update config to get instance B, and the update config again
706+ // the operator will start a new instance, with an increased revision
717707 setup(Mode .NAMESPACED ) { namespace, shinyProxyClient, namespacedClient, stableClient, operator , reconcileListener, recyclableChecker ->
718708 // 1. create a SP instance
719709 val instanceA = ShinyProxyTestInstance (
@@ -776,22 +766,25 @@ class MainIntegrationTest : IntegrationTestBase() {
776766 // 10. wait until instance is created
777767 instanceAPrime.waitForOneReconcile()
778768
779- // 11. wait for delete to happen
769+ // 11. wait for delete of instance A to happen
780770 recyclableChecker.isRecyclable = true
781- while (stableClient.pods().withName( " sp- ${spB.metadata.name} -pod- ${instanceB.hash} " .take( 63 )).get() != null
782- || stableClient.configMaps().withName( " sp- ${spB.metadata.name} -cm- ${instanceB.hash} " .take( 63 )).get() != null
783- || stableClient.services().withName( " sp- ${spB.metadata.name} -svc- ${instanceB.hash} " .take( 63 )).get() != null ) {
784- delay( 1000 )
785- logger.debug { " Pod still exists! " }
771+ instanceA.waitForDeletion(spA)
772+
773+ // 12. assert instance A does not exists anymore
774+ assertThrows< IllegalStateException >( " Instance not found " ) {
775+ instanceA.retrieveInstance( 0 )
786776 }
787777
788- // 12. assert instance B does not exists anymore
778+ // 13. wait for delete of instance B to happen
779+ instanceB.waitForDeletion(spB)
780+
781+ // 14. assert instance B does not exists anymore
789782 assertThrows<IllegalStateException >(" Instance not found" ) {
790783 instanceB.retrieveInstance()
791784 }
792785
793786 // 13. assert instance A' is correct
794- instanceAPrime.assertInstanceIsCorrect(1 , true )
787+ instanceAPrime.assertInstanceIsCorrect(1 , true , 1 )
795788
796789 job.cancel()
797790
@@ -952,7 +945,8 @@ class MainIntegrationTest : IntegrationTestBase() {
952945 assertEquals(mapOf (
953946 LabelFactory .APP_LABEL to LabelFactory .APP_LABEL_VALUE ,
954947 LabelFactory .REALM_ID_LABEL to sp.realmId,
955- LabelFactory .INSTANCE_LABEL to spTestInstance.hash
948+ LabelFactory .INSTANCE_LABEL to spTestInstance.hash,
949+ LabelFactory .REVISION_LABEL to " 0"
956950 ), rule.podAffinityTerm.labelSelector.matchLabels)
957951
958952 job.cancel()
@@ -1002,7 +996,8 @@ class MainIntegrationTest : IntegrationTestBase() {
1002996 assertEquals(mapOf (
1003997 LabelFactory .APP_LABEL to LabelFactory .APP_LABEL_VALUE ,
1004998 LabelFactory .REALM_ID_LABEL to sp.realmId,
1005- LabelFactory .INSTANCE_LABEL to spTestInstance.hash
999+ LabelFactory .INSTANCE_LABEL to spTestInstance.hash,
1000+ LabelFactory .REVISION_LABEL to " 0"
10061001 ), rule.labelSelector.matchLabels)
10071002
10081003 job.cancel()
@@ -1054,7 +1049,8 @@ class MainIntegrationTest : IntegrationTestBase() {
10541049 assertEquals(mapOf (
10551050 LabelFactory .APP_LABEL to LabelFactory .APP_LABEL_VALUE ,
10561051 LabelFactory .REALM_ID_LABEL to sp.realmId,
1057- LabelFactory .INSTANCE_LABEL to spTestInstance.hash
1052+ LabelFactory .INSTANCE_LABEL to spTestInstance.hash,
1053+ LabelFactory .REVISION_LABEL to " 0"
10581054 ), rule.podAffinityTerm.labelSelector.matchLabels)
10591055
10601056 job.cancel()
0 commit comments