arcanemachine
I have a LiveView that tracks how many users are viewing another page. The other page is using Presence to track when users enter and leave. Everything works fine during manual testing.
For my tests, I need to simulate that a user has left the page (closed tab, clicked a link, etc.) so that they no longer appear in the list of users being tracked. I am unable to simulate such an event in my Elixir test code.
In my Elixir test code, how can I simulate that a LiveView user has exited the page?
EDIT: I can use render_click/2 to click a link that happens to be in the view and that does the trick for now, but hopefully there’s something a little less hacky that I can use.
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
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
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
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
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
You could always just kill the process:
If there is a cleaner way I am not sure.
arcanemachine
I tried that, it causes the whole test to fail:
sodapopcan
Dang, I’m also interested, though. I’ve only ever tested this stuff with Wallaby.
Can you post your whole test?
arcanemachine
It’s a really long test, so there’s a lot of cruft. I tried making a barebones version and it’s not crashing the whole test anymore. I’ll poke around for a bit and see if I can find out what is causing the issue.
Thanks for the hint. I have to make dinner so I’ll be back with more info in a bit.
arcanemachine
It looks like killing the LiveView process causes the test to crash pretty much immediately. This example will crash:
I’m in over my head on this one. Until I can figure out how to gracefully end the LiveView processes, I’m just gonna stick to my simulated link-clicking hack.
sa-mm
Try
Process.exit(view.pid, :normal). Docs: Process — Elixir v1.15.5arcanemachine
Using
:normaldoes not appear to have any effect.Here’s a brief version of the test I’ve been working with (it’s for a toy project where multiple users can take a quiz while a teacher supervises the results):
To recap:
Process.exit(quiz_take_view.pid(), :kill)crashes the entire test, andProcess.exit(quiz_take_view.pid(), :normal)appears to have no effect whatsoever (even after a lengthyProcess.sleep(30_000)). Simulating a link being clicked seems to shut down the view gracefully (thus the test can complete successfully), but I have no idea what’s going on behind the scenes (I’ve looked, but there’s a lot going on that goes above my head).Tested on Elixir 1.15.5-otp-26 on Linux.
LostKobrakai
The issue is that two things are started. A LV client and a channel for communication. Both seem to be linked to the test process. Most of that stuff is private though.
stop_supervised(view.pid)seems to work, though with a warning. I’d argue that LV should provide an API to close a view.arcanemachine
Finally got it!
GenServer.stop(view.pid())did the trick.adw632
To simulate a user being unauthenticated and disconnected in all liveviews and channels you can do:
This covered in the documentation here Disconnecting all instances of a live user.