diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2024-02-01 13:55:50 +0000 |
---|---|---|
committer | JvD_Ericsson <jeff.van.dam@est.tech> | 2024-02-07 10:28:52 +0000 |
commit | cc1c83c740d3bde18654098013f2b76eb8fa0567 (patch) | |
tree | 84b7d821c8b2c4fe27e93ea666ef64438116e330 /cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy | |
parent | 72f2fb7eca73cc91338026c734778dd1dcba01b9 (diff) |
Replace sleep with PollingConditions
Issue-ID: CPS-1950
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I0e23c697ef6b5a134295728f352f2dff7be05a62
Diffstat (limited to 'cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy')
-rw-r--r-- | cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/executor/CpsNcmpTaskExecutorSpec.groovy | 25 |
1 files changed, 13 insertions, 12 deletions
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 55590168d..5f62aca68 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') } |