Skip to content

Commit

Permalink
Add unit test for background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 26, 2023
1 parent 0233d0b commit 84562cf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test_socketio.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def on_disconnect_test():
disconnected = '/test'


@socketio.on('connect', namespace='/bgtest')
def on_bgtest_connect():
def background_task():
socketio.emit('bgtest', namespace='/bgtest')

socketio.start_background_task(background_task)


@socketio.event
def message(message):
send(message)
Expand Down Expand Up @@ -762,6 +770,13 @@ def test_encode_decode_2(self):
self.assertEqual(received[0]['args'][0], {'foo': 'bar'})
self.assertEqual(ack, {'foo': 'baz'})

def test_background_task(self):
client = socketio.test_client(app, namespace='/bgtest')
self.assertTrue(client.is_connected(namespace='/bgtest'))
received = client.get_received('/bgtest')
self.assertEqual(len(received), 1)
self.assertEqual(received[0]['name'], 'bgtest')


if __name__ == '__main__':
unittest.main()

0 comments on commit 84562cf

Please sign in to comment.