Comments (2)
Okay, so I managed to figure out when/why this happens...
The scenario is that the connection is closed during establishing of connection in AsyncJsonWebsocketConsumer.connect()
When we open the connection with WebsocketCommunicator.connect()
, the first message is interpreted as "all good, we are connected", and then the second/remaining message in the pipeline is the websocket.close
-one
communicator = WebsocketCommunicator(application, ws_url, headers)
connected, subprotocol = await communicator.connect() # This one consumes the "jwt-expired"-message
msg = await communicator.receive_output()
self.assertEqual(msg, {"type": "websocket.close"})
To test that the jwt-expired
-message is there during connect we have to manually send the websocket.connect
-message:
communicator = WebsocketCommunicator(application, ws_url, headers)
await communicator.send_input({"type": "websocket.connect"})
msg = await communicator.receive_json_from()
self.assertEqual(msg, {"type": "jwt-expired"})
msg = await communicator.receive_output()
self.assertEqual(msg, {"type": "websocket.close"})
self.assertTrue(await communicator.receive_nothing())
from channels.
What's your test code look like?
With WebsocketCommunicator
you'd use receive_json_from
to check the messages as they come in...
from channels.
Related Issues (20)
- Unable to collect code coverage when using `ChannelsLiveServerTestCase` HOT 14
- error in channel layer explanations HOT 2
- adding a check if group_name exists method for channel_layer HOT 1
- Small messages are getting concatenated HOT 2
- How can I change the schema in the database? HOT 1
- Handler declaration by decorator/annotation (in order to prevent potential method leaks) HOT 1
- django-q2 and django-channels together HOT 1
- Channel Layer's group_send() Not Working When Called From Django View HOT 3
- Add CORs middleware HOT 1
- Breakage in routing.py on django/main pre-5.1.
- Use Django async-native APIs where possible HOT 9
- Django Channels Memory Leak on every message or connection HOT 35
- WARNING daphne.server ASGIStaticFilesHandler WebRequest took too long to shut down and was killed HOT 4
- Use group_send() when group is empty HOT 1
- Session Data Corrupted HOT 1
- Error with send_json Function in AsyncJsonWebsocketConsumer HOT 6
- Getting TypeError: SSEConsumer() missing 2 required positional arguments: 'receive' and 'send'
- django.core.exceptions.SynchronousOnlyOperation
- Minor error in documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from channels.