ream88
Wait_for_async_assigns - prevents "DBConnection.ConnectionError: client exited" errors in Phoenix LiveView tests
I’ve been running into DBConnection.ConnectionError: client exited errors in LiveView tests whenever using assign_async/3. The async tasks keep running after the test completes and crash when trying to access the closed database connection.
There’s been an open issue about this for a while, so I extracted a helper function we’ve been using:
test "loads data asynchronously", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/products")
html = render_async(view)
assert html =~ "Products"
wait_for_async_assigns(view)
end
It waits for all async operations to complete before the test exits. The timeout defaults to ExUnit’s assert_receive_timeout but can be configured.
Installation
def deps do
[
{:wait_for_async_assigns, "~> 0.1.0", only: :test}
]
end
Import in your test case module:
defmodule MyAppWeb.ConnCase do
use ExUnit.CaseTemplate
using do
quote do
import Phoenix.ConnTest
import Phoenix.LiveViewTest
import WaitForAsyncAssigns
@endpoint MyAppWeb.Endpoint
end
end
end
The package also includes a Credo check that warns when LiveView tests are missing wait_for_async_assigns/1:
# .credo.exs
%{
configs: [
%{
name: "default",
requires: ["deps/wait_for_async_assigns/lib/credo/check/wait_for_async_assigns.ex"],
checks: %{
enabled: [
{Credo.Check.WaitForAsyncAssigns, []}
]
}
}
]
}
Links: Hex
GitHub:
Popular in Announcing
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir.
https://github.com/ityonemo/zigler
The idea here...
New
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub.
Docs are at OpenaiEx User Gu...
New
I created Kitto a framework for dashboards inspired by Dashing.
The distributed characteristics of Elixir and the low memory footprint...
New
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir.
I...
New
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue.
It’s a seamless integration of Vue and Phoenix LiveView, i...
New
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library.
The progre...
New
Hello all,
I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
Hi! :waving_hand:
I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
New
Other popular topics
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









