diff options
Diffstat (limited to 'cps-ncmp-rest/src')
2 files changed, 16 insertions, 15 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 f06af6c10a..4edbf3569f 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 @@ -44,7 +44,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { 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' + 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', _, _) >> { @@ -54,7 +54,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification { objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false) then: 'the task is executed in an async fashion or not' expectedCalls * spiedCpsNcmpTaskExecutor.executeTask(*_) - and: 'the service request is always invoked within 1 seconds' + and: 'the service request is invoked' new PollingConditions().within(1) { assert networkServiceMethodCalled == true } @@ -97,7 +97,7 @@ 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 within 1 seconds' + and: 'the network service is invoked' new PollingConditions().within(1) { assert networkServiceMethodCalled == true } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy index 55590168d9..5f62aca684 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.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. @@ -28,6 +28,7 @@ import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.slf4j.LoggerFactory import spock.lang.Specification +import spock.util.concurrent.PollingConditions class CpsNcmpTaskExecutorSpec extends Specification { @@ -37,23 +38,23 @@ class CpsNcmpTaskExecutorSpec extends Specification { @BeforeEach void setup() { - ((Logger) LoggerFactory.getLogger(CpsNcmpTaskExecutor.class)).addAppender(logger); - logger.start(); + ((Logger) LoggerFactory.getLogger(CpsNcmpTaskExecutor.class)).addAppender(logger) + logger.start() } @AfterEach void teardown() { - ((Logger) LoggerFactory.getLogger(CpsNcmpTaskExecutor.class)).detachAndStopAllAppenders(); + ((Logger) LoggerFactory.getLogger(CpsNcmpTaskExecutor.class)).detachAndStopAllAppenders() } def 'Execute successful task.'() { when: 'task is executed' objectUnderTest.executeTask(taskSupplier(), enoughTime) - and: 'wait a little for async execution completion' - Thread.sleep(10) then: 'an event is logged with level INFO' - def loggingEvent = getLoggingEvent() - assert loggingEvent.level == Level.INFO + new PollingConditions().within(1) { + def loggingEvent = getLoggingEvent() + assert loggingEvent.level == Level.INFO + } and: 'the log indicates the task completed successfully' assert loggingEvent.formattedMessage == 'Async task completed successfully.' } @@ -61,11 +62,11 @@ class CpsNcmpTaskExecutorSpec extends Specification { def 'Execute failing task.'() { when: 'task is executed' objectUnderTest.executeTask(taskSupplierForFailingTask(), enoughTime) - and: 'wait a little for async execution completion' - Thread.sleep(10) then: 'an event is logged with level ERROR' - def loggingEvent = getLoggingEvent() - assert loggingEvent.level == Level.ERROR + new PollingConditions().within(1) { + def loggingEvent = getLoggingEvent() + assert loggingEvent.level == Level.ERROR + } and: 'the original error message is logged' assert loggingEvent.formattedMessage.contains('original exception message') } |