de.flapdoodle.embed.mongo: Unable to run consecutive test suites due to error
We have two Junit tests that each declare @BeforeClass and @AfterClass methods to setup and tear down the MongodExecutable instance, for example:
@BeforeClass
public static void setupClass() throws Exception {
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(mongoPort, Network.localhostIsIPv6()))
.build();
MongodStarter runtime = MongodStarter.getDefaultInstance();
mongodExecutable = runtime.prepare(mongodConfig);
mongod = mongodExecutable.start();
mongo = new MongoClient("localhost", mongoPort);
db = mongo.getDB("mydb");
}
@AfterClass
public static void tearDownClass() {
if (mongodExecutable != null)
mongodExecutable.stop();
}
Running each of these tests separately works fine, but running in the same suite the second test to run fails and reports:
WARNING: emptying DBPortPool to localhost/127.0.0.1:27017 b/c of error
Followed by a broken pipe error from the code attempting to access the DB.
In the @Before
method for each test we are loading test data by executing db.doEval(...);
and in the @After
we are doing the same with a dropDatabase()
call to clean up.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 18 (8 by maintainers)
Hi, I’ve got same issue, and my tests are passed after adding @DirtiesContext to each test method:
and some test dependencies in build.gradle: