shahryarjb
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
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
shahryarjb
Thank you. I already thought about this and other things you said, but my first problem is that I can’t kill all the children of dynamic-supervisor or a child in unit test, unfortunately
.
this part of my code has error in unit test
https://github.com/mishka-group/mishka_installer/blob/pristance_mnesia_installer/lib/processing_pipelines/queue/queue.ex#L155
Unfortunately, I didn’t think about this from the beginning due to my lack of experience in mnesia, and in the same way, I use mnesia internally, which is very dependent on the module I am using, and it is very difficult to change it with random names. All codes must be rewritten from scratch
https://github.com/mishka-group/mishka_installer/tree/pristance_mnesia_installer
Schultzer
You would need to stop it first ExUnit.Callbacks — ExUnit v1.20.2 and then exit the pids Process — Elixir v1.17.0-rc.1
shahryarjb
Yes, I am using it, but it creates another problem for me :)) for example I lost Phoenix PubSub in my tests. I am trying re-write whole my project.
I think that I directed my project forward very badly, and even if these problems are solved now, they may increase in the future.
shahryarjb
I want to say thank you I got some idea from your code and mix with my code and fix the problem, for now!
https://github.com/mishka-group/mishka_installer/blob/refactor-dependencies/test/event/event_test.exs#L6-L39