From 8c495cd7f1ca3abcac40c099a0f08f12462d4a34 Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Fri, 6 Oct 2023 12:49:44 +0200 Subject: [PATCH] test: close context (#518) * test: close context * Update discovery-client/src/test/groovy/io/micronaut/discovery/consul/MockConfigurationDiscoverySpec.groovy Co-authored-by: Tim Yates --------- Co-authored-by: Tim Yates --- .../test/groovy/io/micronaut/discovery/EagerInitSpec.groovy | 5 ++++- .../consul/ConsulMockConfigurationClientFilesSpec.groovy | 3 +++ .../discovery/consul/MockConfigurationDiscoverySpec.groovy | 5 +++++ .../micronaut/discovery/eureka/EurekaClientConfigSpec.groovy | 3 +++ .../discovery/eureka/health/EurekaHealthIndicatorSpec.groovy | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/discovery-client/src/test/groovy/io/micronaut/discovery/EagerInitSpec.groovy b/discovery-client/src/test/groovy/io/micronaut/discovery/EagerInitSpec.groovy index 035f88ada..a63974326 100644 --- a/discovery-client/src/test/groovy/io/micronaut/discovery/EagerInitSpec.groovy +++ b/discovery-client/src/test/groovy/io/micronaut/discovery/EagerInitSpec.groovy @@ -7,10 +7,13 @@ class EagerInitSpec extends Specification { void 'test run with eager init'() { given: - def context = ApplicationContext.builder().eagerInitSingletons(true).eagerInitConfiguration(true) + ApplicationContext context = ApplicationContext.builder().eagerInitSingletons(true).eagerInitConfiguration(true) .start() expect: "context starts up successfully" context != null + + cleanup: + context.close() } } diff --git a/discovery-client/src/test/groovy/io/micronaut/discovery/consul/ConsulMockConfigurationClientFilesSpec.groovy b/discovery-client/src/test/groovy/io/micronaut/discovery/consul/ConsulMockConfigurationClientFilesSpec.groovy index 27864c49f..a6686b9ef 100644 --- a/discovery-client/src/test/groovy/io/micronaut/discovery/consul/ConsulMockConfigurationClientFilesSpec.groovy +++ b/discovery-client/src/test/groovy/io/micronaut/discovery/consul/ConsulMockConfigurationClientFilesSpec.groovy @@ -120,6 +120,9 @@ not: env.getRequiredProperty('datasource.driver', String) == 'java.SomeDriver' !env.getProperty('not.there', Boolean).isPresent() !env.getProperty('also.not.there', Boolean).isPresent() + + cleanup: + applicationContext.close() } diff --git a/discovery-client/src/test/groovy/io/micronaut/discovery/consul/MockConfigurationDiscoverySpec.groovy b/discovery-client/src/test/groovy/io/micronaut/discovery/consul/MockConfigurationDiscoverySpec.groovy index e57e984e4..512805e70 100644 --- a/discovery-client/src/test/groovy/io/micronaut/discovery/consul/MockConfigurationDiscoverySpec.groovy +++ b/discovery-client/src/test/groovy/io/micronaut/discovery/consul/MockConfigurationDiscoverySpec.groovy @@ -89,6 +89,9 @@ class MockConfigurationDiscoverySpec extends Specification { then:"The value is retrieved again" environment.getProperty('must.override1', String).get() == 'changed' + + cleanup: + applicationContext.close() } void "test multiple environment precedence"() { @@ -161,6 +164,8 @@ class MockConfigurationDiscoverySpec extends Specification { expect: !result.isPresent() + cleanup: + applicationContext.close() } private void writeValue(String env, String name, String value) { diff --git a/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/EurekaClientConfigSpec.groovy b/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/EurekaClientConfigSpec.groovy index bba8d3ba7..94eb5beb0 100644 --- a/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/EurekaClientConfigSpec.groovy +++ b/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/EurekaClientConfigSpec.groovy @@ -39,6 +39,9 @@ class EurekaClientConfigSpec extends Specification { expect: serviceInstances == result + cleanup: + applicationContext.close() + where: value | result 'localhost:8087' | [newServiceInstance("http://$value")] diff --git a/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/health/EurekaHealthIndicatorSpec.groovy b/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/health/EurekaHealthIndicatorSpec.groovy index f9135a634..c81ea54bf 100644 --- a/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/health/EurekaHealthIndicatorSpec.groovy +++ b/discovery-client/src/test/groovy/io/micronaut/discovery/eureka/health/EurekaHealthIndicatorSpec.groovy @@ -51,5 +51,6 @@ class EurekaHealthIndicatorSpec extends Specification { cleanup: eurekaServer?.stop() + applicationContext.close() } }