#testing applications with multiple supervised processes

1 messages · Page 1 of 1 (latest)

faint ruin
#

Hi, I'm trying to build simple backend app with authentication and websockets. The goal is to have the ability for clients to create or join rooms and chat there with other connected clients - nothing complicated. Internally, I have multiple workers (lets say 100_000 supervised actors, ready to be used as room sessions) and a rooms manager, that can get or assign rooms to be used by clients and also send information about what rooms were created. I'm using wisp, mist and squirrel to make everything work, so i also add mist server and pog to a supervisor during app startup.

My brain is not braining when it comes to testing the app. The Context type is:

pub type Context {
  Context(
    conn: pog.Connection,
    jwt_secret: String,
  )
}

I already made some tests for authentication (with wisp/testing module), and I had two functions that I use before every test to create context:

  • mock_context() -> Context for tests that were not requiring any actual Context content.
  • shutdown_context(handle_test: fn(Context) -> Nil) that handles opening db pool and then closing the pool after the test.
    Now I need to expand Context content, by adding rooms manager's subject. I don't really know if it would make sense to start supervisor with all actors needed for each test, so im probably doing something wrong. I should probably start supervisor only once and then work with all proccesses i need (like db connection and manager subject), but i dont really know how to do it. I can't pass assigned names to tests functions during app start, so application's start module will not help me here...

I really hope my question makes sense, as I'm new to OTP and I'm figuring things out myself.

coarse basalt
#

You could use FFI to cheat a little and make a non-unique name

#

Then you can use that name in tests to refer to the connection pool started in the test main function

faint ruin
coarse basalt
#

I don’t think there’s any reason to have a start module that starts an empty supervisor

#

The test setup approach sounds good

faint ruin
# coarse basalt I don’t think there’s any reason to have a start module that starts an empty sup...

oh, i meant that in start module I have my normal supervisor with mist server, 100_000+ rooms with a manager, pog and normal names created inside that start module. And I have env, that checks if im running app in test mode or normal mode, and if its in test mode, start module will start empty supervisor instead. Because start module should return Result(process.Pid, actor.StartError), right..?

coarse basalt
#

What’s test mode?

faint ruin
#

Well, i have makefile that sets APP_MODE=test when running gleam test, and APP_MODE=start when running gleam run... I thought it would be fine to have this 😅

#

so that when running tests, i would create a different supervisor, in test main function

coarse basalt
#

It’s a bit of a shame that the official tooling not longer works

#

And that the application code had to know about the test code