Closed al-awsdev4 closed 9 months ago
I cannot reproduce. I have added a test based on your code to this repository to confirm that background tasks are working fine. See https://github.com/miguelgrinberg/Flask-SocketIO/commit/84562cf876343150bb1c0b2431caf75b280e82cc.
Maybe your background task is crashing for some reason and does not run to completion?
@miguelgrinberg thank you for your quick response. It does not work even my background job contains just logger call:
@socketio.on('connect', namespace='/namespace')
def handle_connect():
def background_task():
app.logger.info('Background task started')
socketio.start_background_task(background_task)
Additional info:
platform linux -- Python 3.8.11, pytest-6.2.5
You can confirm yourself that a similar test just added to this repository passes. I'm really not sure how I can help, given that I cannot debug an issue that I cannot reproduce. You can compare your testing procedures against mine in this repository to help you determine what is causing this.
@miguelgrinberg got it. I'll try to compare and debug more deeply. I'll send feedback as soon as I find the reason.
@miguelgrinberg, our application uses eventlet
async mode, so that's one difference when issue is reproducible.
app = Flask(__name__)
socketio = SocketIO(
logger=True,
engineio_logger=True,
async_mode='eventlet'
)
socketio.init_app(app=app)
I tried different versions of eventlet
but it does not help.
@al-awsdev4 If you are using eventlet during your test run you need to ensure that all the packages that you use to support your tests are compatible with eventlet style concurrency. Not sure which test runner you are using, but I have no idea if unittest, pytest, nose, etc. can be used safely with eventlet. Even if you were able to make your tests work fine in the past, supporting eventlet for unit tests has never been a goal.
@miguelgrinberg, thank you for clarifying. Issue can be closed since it's not related to Socket.IO test client.
Describe the bug We use test case to check custom heartbeat function using background task:
test_heartbeat_handler.py
Expected behavior Log message and updated timestamp are presented.
Additional context It does not work only for test client. Recently it worked on
5.3.4
version. Update to5.3.6
does not help.