Giter Site home page Giter Site logo

Comments (2)

MaZZly avatar MaZZly commented on June 16, 2024 1

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.

carltongibson avatar carltongibson commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.