KikisBomb

KikisBomb

A coworker has written a controller test where he occasionally sends a test request twice in one test using the same connection. Here is an example (lines 81 and 84):


This was not previously a problem as the tests had passed. However, I am modifying the router to require JWT authentication, which involves setting the request header at one point. This causes “(Plug.Conn.AlreadySentError) the response was already sent”. I suspect it has to do with line 84 where the same connection was involved in another request. Is this bad practice? If not, how do I resolve the (Plug.Conn.AlreadySentError)? Thanks

Showing Posts 3 to 1

blatyo

blatyo

Conduit Core Team

If I were doing this, I’d probably do:

result_conn = put conn, ...

# do stuff

result_conn = get conn, ...

That way conn is never rebound and is always the fresh conn provided to the test. However, I agree that making two requests in the same test is probably a code smell.

KikisBomb

KikisBomb OP

Yeah, I’ll make sure to use the markdown in the future.

I inserted conn = recycle(conn) right before the second (conn, path, params), but the headers were not recycled into the new conn. Also, after discussing with my coworker, I am deciding to limit each test to 1 http request. Thanks for the tip though, I’ll consider using recycle in the future for similar issues.

NobbZ

NobbZ

It’s usually fine to reuse the conn, perhaps recycle helps?

If not, I think the big is in your implementation rather than in the tests.

Ps: it’s much easier to read if you actually copy and paste code and annotate it using standard markdown, than to put a screenshot, which is bad for smaller bandwidths or data plans.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
RemyXRenard
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
velrest
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
samoloth
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
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 Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews