Closed andriihorpenko closed 4 years ago
In addition, this is a bot's constructor I'm using(highlighted one, as you see I am not using one with DBContext):
Ahah, with all your opened issues, I've got all this pitfalls :) I created a bean for a db as a temp file. You can create temp db with test profile and a permanent db for a prod profile, but I was lazy to implement this. This is my code
@Bean
fun dbForBot(): DBContext {
val db = DBMaker
.tempFileDB()
// .fileDB(properties.botUsername)
.fileMmapEnableIfSupported()
.closeOnJvmShutdown()
.transactionEnable()
.fileDeleteAfterClose()
.make()
return MapDBContext(db)
}
by default the permanent file db is created in the parent classes constructors
Use MapDbContext::offlineInstance, pass the db to your bot in your setUp. Then on tearDown (@ After), do db.clear; db.close();
You'll need to expose a constructor that calls the super constructor with the DB parameter.
Cool, now it's all good, thanks!
When I run all tests within a class I get this error: "File is already opened and is locked". When I run tests individually everything works like a charm. According to the extended error, bot is trying to work with the database but I am not using it. Also after each test, a file with no extension is created in the project root directory which corresponds to a username of a bot. This is how my
setUp
method with@Before
annotation looks like:Here is the full stacktrace: