wceolin

wceolin

I’m using Mox to mock some modules in my app. Usually, it works fine but I have a function that I’m calling inside FLAME.call/2 and it broke my mock:

FLAME.call(Zoonk.FLAME.ImageOptimization, fn ->
  Zoonk.Storage.optimize!(key, args["size"] || 500)
end)

After I added it to FLAME.call/2, I started getting the following error:

** (Mox.UnexpectedCallError) no expectation defined for Zoonk.Storage.StorageAPIMock.optimize!/2 in process #PID<0.5593.0> with args ["16.png", 500]
             (mox 1.1.0) lib/mox.ex:820: Mox.__dispatch__/4
             (zoonk 0.1.0) lib/storage/storage_context.ex:177: Zoonk.Storage.optimize!/2
             (flame 0.2.0) lib/flame/runner.ex:431: anonymous fn/3 in FLAME.Runner.remote_call/4

I’ve tried calling Mox.allow/3 in test_helper.ex but it didn’t work:

Mox.allow(Zoonk.Storage.StorageAPIMock, self(), fn ->
 GenServer.whereis(Zoonk.FLAME.ImageOptimization)
end)

Any ideas how to make it work inside FLAME.call/2? Thanks!

Showing Posts 1 to 4

al2o3cr

al2o3cr

Zoonk.FLAME.ImageOptimization is the name of the FLAME.Pool process that manages runners. It receives a :checkout message and returns the actual PID of the runner, which is what you’d need to share the mock with.

wceolin

wceolin OP

Thanks for the pointer but I’m not sure I understood it (sorry, I’m very new to Elixir). It looks like:

  • FLAME.Pool is the process that manages runners. That’s the process I need.
  • It receives :checkout messages that returns the PID I need.
  • The code you linked suggests this is happening on the checkout_runner function, which is called on the handle_call callback.

Do I need to listen to a callback somewhere? Doing some GPT-driven research, it suggests I need to call GenServer.call(:flame_pool, :checkout) but that doesn’t seem to return the correct PID. GPT isn’t very good with Elixir, unfortunately.

I know I can probably use set_mox_global (that seems to be what the FLAME codebase is using) but I’d love to understand how this actually works because I feel a bit lost here.

al2o3cr

al2o3cr

There are three processes involved here:

  • the test process, that’s calling Mox functions and the code-under-test
  • a process running with callbacks defined in the module FLAME.Pool, named Zoonk.FLAME.ImageOptimization
  • a runner process, that ultimately tries to call Zoonk.Storage.optimize!

The Mox.allow you posted in the original post is sharing the mock with the second process, but it’s actually needed in the third.


FLAME.call “checks out” a runner and then sends it work; doing a checkout outside of that will return a different runner process from the pool, so that won’t help.


Your options, IMO, are:

  • use Mox globally (with the corresponding loss of concurrency)
  • change your architecture slightly: consider wrapping the FLAME.call in a function and using Mox to replace that. Then, test the code inside the FLAME.call separately.
wceolin

wceolin OP

I see, thanks. I thought there was a way to get the PID of that third process to use with Mox.allow.

I was trying to avoid running tests synchronously. In my initial tests, the runtime doubled from 3s to 6s, but moving those sync tests to a separate module brought it back to 3s. It seems like the best option for now.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews