3

I noticed experimentally that any integration test class annotated with @DataMongoTest does not kill the embedded MongoDB instance it uses. To kill the embedded instance, I have to annotate the test with the annotation @DirtiesContext(classMode = ClassMode.AFTER_CLASS).

@RunWith(SpringRunner.class)
@DataMongoTest
@ContextConfiguration(classes = {MyRepositoryIT.class})
@EnableAutoConfiguration
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class MyRepositoryIT{
   // The tests
}

The problem highlights when you run long pipelines of tests using Maven. The embedded Mongo instances are killed only when the whole testing process terminates.

Is it correct? Am I making something wrong?

I am using Spring Boot 2.2.10, flapdoodle library, JUnit 4, and version 4.0.2 of MongoDB. I am building the system under Windows.

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
  • I had the same problem. After hours of digging through my test code, I found a place where I did not "close the reactive stream" (sorry, I'm new to this reactive paradigm and not yet well versed with terminology). In my case I had the statement `repository.save(entity).doOnNext { repository.findById(it.id!!) }.subscribe { // do something }` but I forgot to `.dispose()` it in the end. When I added this everything worked correctly again. – Partyschaum Nov 29 '21 at 11:53
  • Thanks for the comment. However, I was not using the reactive driver but the blocking one. – riccardo.cardin Nov 29 '21 at 12:45

0 Answers0