channels
channels copied to clipboard
Expand documentation of test wait() method
Regarding this:
https://channels.readthedocs.io/en/latest/topics/testing.html#wait
Call it to wait for an application to exit (you’ll need to either do this or wait for it to send you output before you can see what it did using mocks or inspection)
I think more explanation is necessary.
- What is meant by "exit"? That term does not seem to be defined in the docs or in the code.
- The word "it" is used 3 times in this sentence but it's not clear whether they all refer to the same thing
- What is meant by "or wait for it to send you output"?
- Regarding "you'll need to .... before you can see what it did": why? If I don't use it, what will happen? Is there any downside to using it with every message I send?
- Should this be used as an alternative to receive_json_from (say, if i don't need to inspect the JSON that was returned), or together with it?
(By the way I read the source of this method, but my questions remain.)
Also, the explanation is abstract and I think an example with a concrete application (like websockets) would be very helpful. I am trying to figure out how to use this method in my WebSocket consumers. I have noticed that after I use send_json_to() or connect(), my consumer code is still not being run. If I add a .wait(), sometimes that makes it run, but after sending a second message, .wait() does not help. I don't understand whether .wait() processes one websocket message, or if it terminates the entire websocket connection. Since the doc says "wait for an application to exit", I'm guessing it closes the websocket?
To add to the above, I can't see it explained when I can expect the consumer to run -- is it when I call send_json_to(), or wait(), or receive_json_from()?