spring-cloud / spring-cloud/spring-cloud-config

Adding config-client dependency breaks tests annotated with @DirtiesContext and disregards active profiles

Open
#568 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

We had trouble with setting up centralized configuration due to some of the microservices not passing tests after adding dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

Every test that failed had similar set of annotations, e.g.

@ContextConfiguration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureStubRunner(ids = ['x:y:+:z'])
@DirtiesContext
@ActiveProfiles("test")
class ClientFacadeTest extends Specification {

After some investigation I've found out that after adding the dependency the test ignores @ActiveProfiles("test") annotation when @DirtiesContext is also present.

Here are the logs:

2016-11-25 14:30:09.927  INFO 14661 --- [           main] p.e.e.edge.facades.ClientFacadeTest      : The following profiles are active: test
2016-11-25 14:30:10.555  WARN 14661 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-11-25 14:30:13.910  INFO 14661 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@99c5646: startup date [Fri Nov 25 14:30:13 CET 2016]; root of context hierarchy
2016-11-25 14:30:13.924  INFO 14661 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-11-25 14:30:13.935  INFO 14661 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$4aa19e37] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-11-25 14:30:14.058  INFO 14661 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://x:y
2016-11-25 14:30:14.512  INFO 14661 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=..., profiles=[default], label=master, version=e7b904e7185df9cea4b597d4db0bf45093a7d040
2016-11-25 14:30:14.512  INFO 14661 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='.../application.yml']]]
2016-11-25 14:30:16.601  WARN 14661 --- [           main] o.s.c.n.a.ArchaiusAutoConfiguration      : Netflix ConfigurationManager has already been installed, unable to re-install

The most interesting is the 1st and the 7th line, we have: The following profiles are active: test and Located environment: name=..., profiles=[default].

Workaround

To make it work I had to add profile seeting here:

@SpringBootTest(value = "spring.profiles.active=test", webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with spring-cloud-starter-config and the shown @ContextConfiguration, @SpringBootTest, @DirtiesContext, and @ActiveProfiles("test") annotations. Compare the active profile reported by the test with the profiles sent during the config-server lookup; done means the test profile is respected without setting spring.profiles.active in @SpringBootTest.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.