Fix the tests that failing irregularly in groovy pipeline 43/140843/2
authorhalil.cakal <halil.cakal@est.tech>
Tue, 6 May 2025 12:40:46 +0000 (13:40 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Tue, 6 May 2025 16:01:47 +0000 (17:01 +0100)
- Don't check if the key is present in the map anymore instead keep
  looking for if the key deleted after TTL period
- Optimize the test by reducing the max wait time from 10 seconds to 1
  second

Issue-ID: CPS-2798

Change-Id: Ibbd40e682c28fa0c52da3f07d3687927fa42aa02
Signed-off-by: halil.cakal <halil.cakal@est.tech>
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/SynchronizationCacheConfigSpec.groovy

index 7db9e5a..1cecbbe 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START========================================================
- *  Copyright (C) 2022-2025 Nordix Foundation
+ *  Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -105,23 +105,19 @@ class SynchronizationCacheConfigSpec extends Specification {
     }
 
     def 'Time to Live Verify for Module Sync Semaphore'() {
-        when: 'the key is inserted with a TTL of 1 second (Hazelcast TTL resolution is seconds!)'
-            moduleSyncStartedOnCmHandles.put('testKeyModuleSync', 'toBeExpired' as Object, 1, TimeUnit.SECONDS)
-        then: 'the entry is present in the map'
-            assert moduleSyncStartedOnCmHandles.get('testKeyModuleSync') != null
-        and: 'the entry expires'
-            new PollingConditions().within(10) {
+        when: 'the key is inserted with a TTL'
+            moduleSyncStartedOnCmHandles.put('testKeyModuleSync', 'toBeExpired' as Object, 100, TimeUnit.MILLISECONDS)
+        then: 'the entry expires within a second'
+            new PollingConditions().within(1) {
                 assert moduleSyncStartedOnCmHandles.get('testKeyModuleSync') == null
             }
     }
 
     def 'Time to Live Verify for Data Sync Semaphore'() {
-        when: 'the key is inserted with a TTL of 1 second'
-            dataSyncSemaphores.put('testKeyDataSync', Boolean.TRUE, 1, TimeUnit.SECONDS)
-        then: 'the entry is present in the map'
-            assert dataSyncSemaphores.get('testKeyDataSync') != null
-        and: 'the entry expires'
-            new PollingConditions().within(10) {
+        when: 'the key is inserted with a TTL'
+            dataSyncSemaphores.put('testKeyDataSync', Boolean.TRUE, 100, TimeUnit.MILLISECONDS)
+        then: 'the entry expires within a second'
+            new PollingConditions().within(1) {
                 assert dataSyncSemaphores.get('testKeyDataSync') == null
             }
     }