kamaroly
I have been experiencing extremely slow tests for each test behind a protected route with Ash authentication. 54 tests are taking 47 seconds. I tried various tips available online including config :bcrypt_elixir, :log_rounds, 1 but it didn’t help. Meanwhile others are ble to run 376 tests in 7 seconds. How do you speed up your tests?
376 tests in 7 seconds: Anthony Accomazzo on X: "@elixirlang `make signoff` in action: https://t.co/EqDWRGaTsp" / X
My experience:
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
They will simply generate a token for the user and set it into the conn, for example, as opposed to first going through authentication flow.
kamaroly
The approach I am using is to create a user, then add a
user_subjectin the connection that will be used for protected routes.I could also reduce this time if there was a way of signing in once at the beginning for all tests instead of having to sign in on every test. Do you know to sign in once before all tests begin?
Something like setup function be for all tests in the suite.
zachdaniel
There is a setup_all that you can run at the start of each test to ensure your test user is created. It doesn’t happen in the sandbox, so won’t be rolled back on each test. So each test could check first if the user exists and create it otherwise, or do an upsert into the user’s table.
And your
config :bcrypt_elixir, log_rounds: 1is inconfig/test.exs?kamaroly
Yes. I have it configured. See: https://github.com/kamaroly/hr/blob/dev/config/test.exs#L29
zachdaniel
kk. And you’re able to confirm that the majority of your test duration is taken up doing sign in?
kamaroly
Yes. like 90% of my tests require login.
zachdaniel
You should just be able to generate a token for your test user. There is no need to validate their password. How are you generating the
user_subject?bcryptshouldn’t even really come into the picture right? Well…I guess it does to hash their password. But withlog_roundsconfigured to 1 it should be very fast. Feels like something else might be a factor?kamaroly
I’d like also to mention that I am using Ash multitenancy, thus, here’s what happens every time I need to tests a protected age:
I think if there’re could be a way of doing step 1 to 5 once for all. It would significantly speed up the tests.
Here’s the test login function: https://github.com/kamaroly/hr/blob/005b42a185106442b8f8820bfd85c04f4d38192b/test/support/auth_case.ex#L37
Here’s a form test:
https://github.com/kamaroly/hr/blob/dev/test/hr_web/live/organisations/job_titles/form_live_test.exs
zachdaniel
you can do that for each test using setup_all, or for all tests in your test_helper file IIRC.
kamaroly
Here is what I did to reduce the testing time.
I created a fake hash provider to skip the
bycrypthashing in while testing. This improved test speed to over 50%.Then, I made it configurable in config/test.exs like the following