phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.36k stars 2.87k forks source link

Should we use `async: true` on all generated tests? #3134

Closed josevalim closed 4 years ago

josevalim commented 5 years ago

Now that we have the SQL sandbox, we can async: true all tests. The question though is that this only actually applies for Postgrex, so we may need a generator flag to control this behaviour.

ericmj commented 5 years ago

This may be a confusing default. Today you have to presumably learn about async tests and their pitfalls before enabling them. This change will make it more likely to experience the pitfalls before you have learned how to solve them or even know that the issue is caused by async tests. Combined with the nature of test race conditions where you may hit them a while after you originally created the bug can make this a pretty bad experience.

stevedomin commented 5 years ago

@josevalim didn't Ecto always ship with a SQL sandbox?

mikemorris commented 5 years ago

I'd lean towards async: true for all generated tests (with a flag for Postgrex-only currently), and rely on generated tests and documentation as a way of conveying the benefits of async tests and providing patterns for how to write them effectively.

It's much easier to increase adoption of functionality if it's a default, and IMHO this is good direction to push in for guiding users towards writing better tests.

Some tips on documentation language that may help explain async tests can be found in ava, a JavaScript framework that runs tests in parallel by default and describes them as "atomic" tests.

mikemorris commented 5 years ago

@stevedomin I'm assuming this is referring to https://hexdocs.pm/phoenix_ecto/Phoenix.Ecto.SQL.Sandbox.html, an implementation on top of https://hexdocs.pm/ecto/2.0.2/Ecto.Adapters.SQL.Sandbox.html

stevedomin commented 5 years ago

@mikemorris for some reason I assumed José was talking about something new in Ecto 3.0 :)

josevalim commented 5 years ago

Oops, accident. :)

popo63301 commented 5 years ago

@ericmj How can we learn about those pitfalls?