ejpcmac
Hello everybody!
I’ve discovered property-testing with stream_data a few months ago. Since then, I’ve successfully re-written the tests of a library, and I’m willing to use property-testing everywhere I can.
I’ve tried to property-test a Phoenix context boundary, but I’m facing performance issues:
defmodule Kakte.AccountsTest
use Kakte.DataCase
alias Kakte.Accounts
alias Kakte.Repo
[...]
property "list_users/0 returns all users" do
# user_attrs/0 is a generator for valid user attributes.
check all attrs_list <- uniq_list_of(user_attrs(), length: 5) do
Repo.transaction(fn ->
users =
Enum.map(attrs_list, fn attrs ->
{:ok, user} = Accounts.register(attrs)
user
end)
users_list = Accounts.list_users()
assert length(users) == 5
Enum.each(users, fn user -> assert user in users_list end)
Repo.rollback(:done)
end)
end
end
[...]
end
Running this test takes more than 2.5 seconds on my machine. I know a property-test is expected to be longer to execute due to higher number of tests, but 2.5 seconds for one test is way too long IMO. I’ve tried to replace the test body by assert true and it runs quick, so I presume this is due to many repo transactions, but maybe I am misleading.
I have basically three questions:
- Is it a good idea to use property-testing everywhere?
- Do you property-test your Phoenix applications?
- How can I manage to speed up this test?
For information, the context source is here on GitHub.
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!
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
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
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
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
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
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
- #blog-post
- #ai
- #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)
idi527
It depends on what you are testing in this case, and whether if can be accomplished with unit tests. Maybe you can separate the test above into property tests on
changesetfunctions and then a unit test on “list_users/0 returns all users”. However, if you do need to touch the database in your property tests (for example, if you use stateful property tests for state machines backed by postgres), then maybe try reducing the complexity of the tests (with:numtests,:max_sizeproper or propcheck options andsizedmacro) so that they don’t run for too long during development.It might be okay if you leave them to run overnight on some remote testing server, then you’d have a higher confidence that the code works as expected.
UPDATE: There are similar options for stream data as well.
ejpcmac
Yes, that seems to be a good idea. Thank you.
That’s what I did to get a bit more speed, but I feel less confident with fewer tests.
How would you do that? With an environment variable, like
MIX_MAX_RUNS=100 mix testand writing something like this?idi527
I’d create an additional testing mix environment (in addition to
test) which will be more similar toprodthandev, as in it would have remote (not a single local one like withdevor defaulttest) databases to test possible race conditions, higher number of test iterations, mocks replaced with real internal services etc.keathley
This is the trade off with property tests. You’re asking the computer to do a lot of work for you. But in return you’re gaining greater confidence in your overall system because your tests are working to find edge conditions in your logic. If you don’t feel like the trade-off is worth it then that’s a pretty clear indicator that your logic probably isn’t complex enough to warrant spending the time on a property test for it.
A potentially better use for property tests might be to actually drive this out from an api or webpage. Testing with more pieces in integration might help you find more edge cases. You can either generate api requests or use state machine models to drive a fake browser, etc.
Property tests provide robustness. But you pay for it in test time. I think people get hung up on tests times and I would always take robustness over test speed. That said, not every application needs that level of robustness and you still want to ensure that your spending your test time on the pieces of your system that need that level of robustness.
LostKobrakai
Most of that time is probably due to you hitting the database. You’ll get much better times for testing pure computation.