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