Comments (10)
If the client is in the room, then any messages sent to that client should appear in the test client's get_received
. If the client is not in the room, then the messages will not be sent to that client or test client.
from flask-socketio.
@shivansh-vishwakarma in the example you provided, your test sends this event:
self.socketio_test_client.emit('your_event', {'data': 'test'})
But your server does not have an event handler for your_event
. What was the expected outcome in this case? As far as I can see, your test is incorrect. You are sending an unknown event to the server, so the test client gets no reply. I added this missing event handler and test started to pass:
socketio.on('your_event')
def your_event(data):
emit('got it')
Am I missing anything?
from flask-socketio.
@shivansh-vishwakarma Please provide a complete and runnable example test that shows the problem and I'll investigate.
from flask-socketio.
Hope this helps.
Do let me know if you need anything that'll help you in the investigation
class TestSocketEmit(TestCase):
def setUp(self):
self.client = app.test_client()
self.api_key = "API_KEY"
self.socketio_test_client = SocketIOTestClient(app, socketio=socketio, headers={'x-api-key': self.api_key})
self.socketio_test_client.connect(headers={'x-api-key': self.api_key})
def test_websocket_emit(self):
self.socketio_test_client.emit('your_event', {'data': 'test'})
response = self.socketio_test_client.get_received()
def tearDown(self):
self.socketio_test_client.disconnect()
In the given code the response
is[]
from flask-socketio.
How is this any different than the many tests in this repository's test suite? I wanted to see a complete and runnable example, because this feels like it is a problem in your own setup, not in this package. Please provide a complete example that includes the application to be tested.
from flask-socketio.
@miguelgrinberg This should suffice the requirement. I've abstracted out the functionality of flask and socket to reproduce the same with minimal code.
If we can make it work here, it'll work in my project as well.
https://github.com/shivansh-vishwakarma/flask-socket-scratch
from flask-socketio.
One more thing that i noticed which abstracting the functionality was,
If we emit an event to the main application server in the src code using SocketIO.emit()
Then i get response in the get_received()
method. but while doing it with SocketIOTestClient.emit()
it doesn't work out.
Might be helpful in the investigation.
from flask-socketio.
Okay, thanks. This is actually a different bug in Flask-SocketIO, I will have a fix in the next couple of days.
from flask-socketio.
Also, Can you confirm if there is support to emit messages to a particular room using SocketIOTestClient
and receive the messages from a particular room using get_received
or some other function. I tried but couldn't find it.
from flask-socketio.
No, your are correct. My bad @miguelgrinberg
from flask-socketio.
Related Issues (20)
- Support for once to listen for an event only 1 time (Like official socket.io server has) HOT 1
- Error when using gevent with allow_unsafe_werkzeug HOT 2
- Option to redirect http to https instead of raising errors HOT 1
- Strange Behavior with RabbitMQ and Flask-SocketIO HOT 4
- get_received(namespace=None) does not returns the messages HOT 5
- Add type hints HOT 9
- Socket.IO test client does not run background task HOT 7
- gevent - cannot enter into function. HOT 1
- Multiple SocketIO instances connected to the same Flask server HOT 1
- python-engineio and python-socketio version matching with Flask-SocketIO >= 5.3.0 HOT 1
- Flask-SocketIO cannot run in ws HOT 1
- pyinstaller Packaging error HOT 1
- How do I intercept event events and authenticate them in a unified manner?
- Waiting for client events leads to timeouts
- Sending events in a separate thread with delays does not send HOT 1
- Sending high volume of packets in short amount of time causes packets dropping HOT 5
- Namespace catch-all handling? HOT 15
- Namespace catch-all handling of connect/disconnect events HOT 1
- Is Eventlet Still The Best Option? 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 flask-socketio.