summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/test
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2024-01-11 11:57:17 +0000
committerJvD_Ericsson <jeff.van.dam@est.tech>2024-01-18 11:58:51 +0000
commit76f2021e559cd8ab5cf08e26d5aa4533e3d46309 (patch)
treee225107da38b92926a8e130231f4e3e61627ff94 /cps-ncmp-rest/src/test
parent2dce7ab2fd627450550666e3993e28e10f6a8548 (diff)
Use PollingConditions to improve intermittent test failure
Set timeOutInMilliSeconds to 100 (default was 0) Issue-ID: CPS-1950 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I0028f0cd5e5e89d979d4200df77dbd7a42105622
Diffstat (limited to 'cps-ncmp-rest/src/test')
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy28
1 files changed, 18 insertions, 10 deletions
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
index ae7c56458d..f06af6c10a 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
+ * Copyright (C) 2023-2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,19 +37,27 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
def objectUnderTest = new NcmpPassthroughResourceRequestHandler(spiedCpsNcmpTaskExecutor, mockNetworkCmProxyDataService)
+ def setup() {
+ objectUnderTest.timeOutInMilliSeconds = 100
+ }
+
def 'Attempt to execute async get request with #scenario.'() {
given: 'notification feature is turned on/off'
objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled
+ and: ' a flag to track the network service call'
+ def networkServiceMethodCalled = false
+ and: 'the (mocked) service will use the flag to indicate if it is called'
+ mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _) >> {
+ networkServiceMethodCalled = true
+ }
when: 'get request is executed with topic = #topic'
objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false)
- and: 'wait a little for async execution (only if expected)'
- if (expectedCalls > 0) {
- Thread.sleep(500)
- }
then: 'the task is executed in an async fashion or not'
expectedCalls * spiedCpsNcmpTaskExecutor.executeTask(*_)
- /*and: 'the service request is always invoked'
- 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _)*/
+ and: 'the service request is always invoked within 1 seconds'
+ new PollingConditions().within(1) {
+ assert networkServiceMethodCalled == true
+ }
where: 'the following parameters are used'
scenario | notificationFeatureEnabled | topic || expectedCalls
'feature on, valid topic' | true | 'valid' || 1
@@ -89,9 +97,9 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
objectUnderTest.executeRequest('myTopic', dataOperationRequest)
then: 'the task is executed in an async fashion'
1 * spiedCpsNcmpTaskExecutor.executeTask(*_)
- and: 'the network service is invoked (wait max. 5 seconds)'
- new PollingConditions(timeout: 30).eventually {
- //TODO Fix test assertion
+ and: 'the network service is invoked within 1 seconds'
+ new PollingConditions().within(1) {
+ assert networkServiceMethodCalled == true
}
where: 'the following datastores are used'
datastore << ['ncmp-datastore:passthrough-running', 'ncmp-datastore:passthrough-operational']