Hello everyone, I’m building an app using mnesia as storage, and I got a some questions:
-
How to correctly test modules which using the mnesia?
As example: I have an app with 3 genservers which contain callbacks for CRUD under specific supervisor. Every single genserver works with specific table. Im adding the tests for this 3 genserver, testing scenarios and thesetup
block (into every script file of course) with:mnesia.clear_table(:my_table)
inside.-
If Im trying to call this scripts one by one - everything is ok. Troubles begins when I’m calling all tests at once. As I understand, :mnesia works asyncroniously, and tables do not have time to change their state between two or more testing scenarios. As result: sometimes testing scripts works correctly, sometimes not.
-
Sometimes i got message like
disk_log: repairing '__FILE__'
. All appearance, I see this message because:mnesia
are not stopped correctly after ExUnit complete (I think it is perceived like a sudden shutting down for mnesia, working ends off and formed the difference between data in file on disk and data in RAM).What can I do, for fix this message reason? Maybe exist some way for stop the
:mnesia
correctly when all test scenarios is complete?
How do I clean/drop/change state properly the mnesia table(s)/schema(s) for making a tests wich gonna work stable and predictably?
-
-
How to correctly create mnesia schema & start the mnesia in app?
Basically, I have a 2 way, start it manually or add mnesia intoextra_applications
inmix.exs
. I choosed first option. I’ve choosed this way, because if I add mnesia intoextra_applications
- I will have to stop it before calling:mnesia.create_schema
(I’m creating the schema & starting mnesia insideinit/1
of supervisor).Is it good way or not? I don’t know why, but I feel that it’s - anti-pattern.
Is this practice if correct? Creating the schema inside supervisor’s
init/1
. Or I should apart the creating schema/tables from supervisor logic? If yes - how can I create schema/tables correctly in application deployment?If you have some advices, examples or something else, which can help me with this questions - I would be appreciative.