title: Very slow start up for Spring Boot tests with Embed Mongo DB
body: <p>Even run one test you need more than 1 minute:</p>
  
  <ul>
  <li>Startup for embed Mongo ~1 minute</li>
  <li>test execution ~3-8 seconds</li>
  </ul>
  
  <p>I can't understand what is the reason for such behaviour?<br>
  Following is snipped from console:</p>
  
  <pre><code>2018-12-13 13:14:43.214  INFO 12277 --- [           main] c.j.s.embedmongo.EmbeddedMongoBuilder    : Initializing embedded MongoDB instance
  2018-12-13 13:14:43.293  INFO 12277 --- [           main] d.f.embed.process.store.Downloader       : Extract /Users/nazar/.embedmongo/osx/mongodb-osx-ssl-x86_64-3.6.5.tgz : starting...
  2018-12-13 13:14:44.287  INFO 12277 --- [           main] d.f.embed.process.store.Downloader       : Extract /Users/nazar/.embedmongo/osx/mongodb-osx-ssl-x86_64-3.6.5.tgz : extract mongodb-osx-x86_64-3.6.5/bin/mongod
  2018-12-13 13:14:44.288  INFO 12277 --- [           main] d.f.embed.process.store.Downloader       : Extract /Users/nazar/.embedmongo/osx/mongodb-osx-ssl-x86_64-3.6.5.tgz : nothing left
  2018-12-13 13:14:44.288  INFO 12277 --- [           main] d.f.embed.process.store.Downloader       : Extract /Users/nazar/.embedmongo/osx/mongodb-osx-ssl-x86_64-3.6.5.tgz : finished
  2018-12-13 13:14:44.289  INFO 12277 --- [           main] c.j.s.embedmongo.EmbeddedMongoBuilder    : Starting embedded MongoDB instance
  2018-12-13 13:14:45.467  INFO 12277 --- [           main] d.f.embed.mongo.MongodExecutable         : start de.flapdoodle.embed.mongo.config.MongodConfigBuilder$ImmutableMongodConfig@55fee662
  2018-12-13 13:14:45.871  INFO 12277 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:50770], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
  2018-12-13 13:14:45.985  INFO 12277 --- [localhost:50770] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:1}] to localhost:50770
  2018-12-13 13:14:45.990  INFO 12277 --- [localhost:50770] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:50770, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 5]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=4065087}
  2018-12-13 13:14:46.627  WARN 12277 --- [           main] c.t.p.p.configuration.BugsnagConfig      : Bugsnag apikey not set, not using it
  2018-12-13 13:14:46.702  INFO 12277 --- [           main] c.t.p.p.c.AsyncConfigurationTest         : Creating sync task executor for tests
  2018-12-13 13:15:38.019  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : note: noprealloc may hurt performance in many applications
  2018-12-13 13:15:38.057  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.056+0200 I CONTROL  [initandlisten] MongoDB starting : pid=12460 port=50789 dbpath=/var/folders/95/6cdccp1s629gtfwm5tjb63gr0000gp/T/embedmongo-db-8535bf9e-fdc6-44f3-88c8-4bc77dd60bb3 64-bit host=sdos-MacBook-Pro.local
  2018-12-13 13:15:38.057  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] db version v3.5.5
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] git version: 98515c812b6fa893613f063dae568ff8319cbfbd
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] allocator: system
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] modules: none
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] build environment:
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten]     distarch: x86_64
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten]     target_arch: x86_64
  2018-12-13 13:15:38.058  INFO 12277 --- [       Thread-7] o.s.b.a.mongo.embedded.EmbeddedMongo     : 2018-12-13T13:15:38.057+0200 I CONTROL  [initandlisten] options: { net: { bindIp: "127.0.0.1", http: { enabled: false }, port: 50789 }, security: { authorization: "disabled" }, storage: { dbPath: "/var/folders/95/6cdccp1s629gtfwm5tjb63gr0000gp/T/embedmongo-db-8535bf9e-fdc6-44f3-88c8-4bc77dd60bb3", journal: { enabled: false }, mmapv1: { preallocDataFiles: false, smallFiles: true }, syncPeriodSecs: 0.0 } }
  </code></pre>
  
  <p>Here is: <a href="https://pastebin.com/YWsJehmY" rel="nofollow noreferrer">full console log</a></p>
  
  <p>It stucks the most after the line:</p>
  
  <blockquote>
    <p>c.t.p.p.c.AsyncConfigurationTest: Creating sync task executor for tests</p>
  </blockquote>
  
  <p>Here is a snippet from <code>pom</code> file:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;2.1.0.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;de.flapdoodle.embed&lt;/groupId&gt;
          &lt;artifactId&gt;de.flapdoodle.embed.mongo&lt;/artifactId&gt;
          &lt;version&gt;2.1.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;cz.jirutka.spring&lt;/groupId&gt;
          &lt;artifactId&gt;embedmongo-spring&lt;/artifactId&gt;
          &lt;version&gt;1.3.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>No additional plugins, only <code>spring-boot-maven-plugin</code>.<br>
  Also, no additional configuration at <code>application.yml</code> for tests.</p>
  
  <p>Mongo configuration is next:</p>
  
  <pre><code>@Configuration
  public class MongoConfig {
  
      private static final String MONGO_DB_URL = "localhost";
      private static final String MONGO_DB_NAME = "embeded_db";
  
      @Bean
      public MongoTemplate mongoTemplate() throws IOException {
          EmbeddedMongoFactoryBean mongo = new EmbeddedMongoFactoryBean();
          mongo.setBindIp(MONGO_DB_URL);
          MongoClient mongoClient = mongo.getObject();
          return new MongoTemplate(mongoClient, MONGO_DB_NAME);
      }
  }
  </code></pre>
  
  <p>Task execuotor configuration:</p>
  
  <pre><code>@Slf4j
  @Configuration
  @Profile("test")
  public class AsyncConfigurationTest {
  
      @Bean
      @Primary
      public TaskExecutor taskExecutor() {
          log.info("Creating sync task executor for tests");
          return new SyncTaskExecutor();
      }
  }
  </code></pre>
  
  <p>Test looks next:</p>
  
  <pre><code>@Slf4j
  @SpringBootTest
  @ActiveProfiles("test")
  @RunWith(SpringRunner.class)
  public class ServiceTest extends BaseDataServiceTest {
  
  @Value("classpath:enter/enter_file.pdf")
  private Resource enterPdf;
  @Value("classpath:enter/expected.json")
  private Resource enterExpectedJson;
  
  @Test
  public void testEnterDemoDocument() {
      testHelper(enterPdf, enterExpectedJson);
  }
  </code></pre>
  
  <p>Everything works fine. However, the speed is very slow for now.<br>
  How to investigate what is a bottleneck for it? </p>
  
  <p><strong><em>What could be the reason for such slow startup?</em></strong> </p>