mmyers
I’m exploring different ways of interfacing with C code, and in testing C-Nodes, my ExUnit tests were failing randomly. I start the C-Node process using Port.open. And I found that if I call Process.sleep(50) after opening the Port, then all the tests succeed.
Is this a good way to do it?
Is there a better way to wait for the C-Node to be ready to accept a connection?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 7 of 7 Posts
ityonemo
Use net_kernel.monitor_nodes/2, then launch, the wait to have a nodeup message delivered to your test and block on a receive; then continue with your tests.
mmyers
I’m not sure
:net_kernel.monitor_nodeswill give me what I’m looking for. I want to know when it is safe to connect to the C-Node. And according to the Erlang docs:Maybe just a retry with a timeout or limit on the number of retries will work.
benwilson512
How would the C node be connected, but not ready to be connected to?
mmyers
Exactly. The C-Node is not connected initially, which is why net_kernel.monitor_nodes won’t work.
There is a delay between starting the C-Node process, and the C-Node having an open socket, ready to receive a connection from an Elixir/Erlang node. That delay is what I want to account for with something better than a fixed sleep time.
benwilson512
Which is what the messaging solution provides. You
:net_kernel.monitor_nodes, and thenreceive dowith a pattern to wait for the nodeup message.mmyers
Thanks for your feedback. I have a solution.
The problem I was seeing in my tests occurred when trying to send a message before the C node was listening.
Comments from @benwilson512 and @ityonemo made me think, “What if the C node initiated the connection back to the Elixir node, instead of the other way around?” And maybe that’s how they were thinking it worked (or should have worked) in the first place. The initial code was just from sample C node code found on online, where the C node published itself to Epmd and listened, waiting for Elixir nodes to connect, as diagrammed above.
So I changed the C node to initiate the node connection, rather than just waiting for a connection:
And after I remembered that C nodes are
hidden, and used:net_kernel.monitor_nodes(true, node_type: :hidden), then I did get a:nodeupmessage!This also simplified the code on the C node side, I can just call ei_connect, and don’t have to use ei_listen, ei_publish and ei_accept.
ityonemo
shoot! I should have been more specific and reminded you that C nodes are hidden.