shahryarjb
Cant reset Mnesia or a DynamicSupervisor in ExUnit setup for each test
Hello friends, this is my cleaner of Mnesia and Job terminator inside one of my test module, and I try to summarize the codes in another step.
My whole code:
setup do
Code.ensure_loaded?(PluginWorker)
:ok = :mnesia.start()
:mnesia.create_schema([node()])
:mnesia.create_table(Queue, Queue.database_config())
:mnesia.create_table(Event, Event.database_config())
:ok = :mnesia.wait_for_tables([Queue, Event], 5000)
:persistent_term.put(:event_status, "ready")
MishkaInstaller.subscribe("event")
Queue.new(%{
worker: PluginWorker,
error: %{type: :continuously, max_try: 5, delay: 0}
})
on_exit(fn ->
:ok = MishkaInstaller.unsubscribe("event")
:ok = MishkaInstaller.unsubscribe("queue:job")
Job.terminate_worker(PluginWorker)
Queue.delete(worker: PluginWorker)
{:atomic, :ok} = :mnesia.clear_table(Queue)
{:atomic, :ok} = :mnesia.clear_table(Event)
:ok = :mnesia.delete_schema([node()])
:stopped = :mnesia.stop()
end)
:ok
end
As I summarize this I have 2 lines; the first one create inside Mnesia and the other terminate the job which is a PartitionSupervisor -> DynamicSupervisor
Queue.new(%{
worker: PluginWorker,
error: %{type: :continuously, max_try: 5, delay: 0}
})
#####
Job.terminate_worker(PluginWorker)
Now what is my problem; it terminates the job pid and returns the ok response, but again when I want to create I can see the job is not terminated!!
This is my terminate function
def terminate(pid) do
DynamicSupervisor.terminate_child(
{:via, PartitionSupervisor, {MishkaJobWorkerSupervisor, self()}},
pid
)
end
I can not be able to reset all things for each test what you suggest me for this?
by the way, I forced to change all dirty way of my mnesia to transaction to lock the data when is writing!! but the problem is my
DynamicSupervisor.
Thank you in advance
Most Liked
Schultzer
Regarding resetting mnesia: This is how I run test with mnesia in ecto_qlc ecto_qlc/test/support/data_case.ex at main · Schultzer/ecto_qlc · GitHub I usually create a temp directory for the data. But I guess you could always test in memory with a random name for your schema, and lastly, you might be able to wrap the test in a transaction, akin to how ecto sandbox works.
Schultzer
You would need to stop it first ExUnit.Callbacks — ExUnit v1.16.3 and then exit the pids Process — Elixir v1.17.0-rc.1







