-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] bus: enable websocket during tours #189859
base: master
Are you sure you want to change the base?
Conversation
f0c3495
to
7772214
Compare
ddc6b7b
to
ea69a83
Compare
9dd6c11
to
94fbc8b
Compare
8f1a17f
to
a5f7d5d
Compare
f734131
to
9c92bce
Compare
383e04e
to
97144da
Compare
df40c3a
to
aa3fa7e
Compare
e09df52
to
0f03647
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed websocket and python bus code.
disconnect()
was a public API and was called from other threads, that method was directly writing on the underlying buffer. This can cause a serialization problem if the websocket (or other threads calling disconnect()
) are writing on the socket at the same time.
The solution to that problem, implemented in the new close
method: instead of writing directly on the buffer, it writes on a thread-safe queue which is consumed by the websocket thread to write on the socket. So there is only ever the websocket thread that writes on the socket, eliminating serialization errors.
There are critical sections around the usages of the _waiting_for_dispatch
boolean. We made sure that "at worst" it would force the websocket to poll the bus one more time, than to loose some notifications.
I am not too sure about the precommit.call()
and postcommit.call()
inside the browser_js()
method.
Previously, a socketpair was used to wake up the WebSocket event loop for notifications. This method is too restrictive, as it doesn't allow communication with the event loop in other scenarios. For example, the disconnect method is not thread-safe and should only be used in the WebSocket thread. However, situations like server shutdown or test cleanup require closing WebSockets from outside the event loop thread. This PR enhances communication with the WebSocket event loop: - The `socketpair` is replaced by a pollable queue that allows controlling the WebSocket instances from outside of the event loop. - Two control commands are available for now: `CLOSE` and `DISPATCH`. This approach allows for the future addition of more commands. - The `disconnect` method is removed from the public API: This method is not thread-safe and should only be called from internal code running in the WebSocket thread. - Expose the `close` method to the public API, which relies on the command queue to properly order disconnections from outside the WebSocket thread. task-3970199
This PR adapts the `Websocket` and `HttpCase` classes to enable WebSockets during tours. Modules such as point of sale or discuss cannot be properly tested without the bus. task-3970199
Enabling WebSockets during tour highlighted issues with some tours. This PR corrects those tours. task-3970199
0f03647
to
ba18006
Compare
This PR aims to enable WebSocket functionality during tours. Applications that rely heavily on the bus, such as Discuss or POS, require the bus connection to be active to write relevant tests.
1. Allow to close websockets from outside of the event loop
Previously, a socketpair was used to wake up the WebSocket event loop for notifications. This method is too restrictive, as it doesn't allow communication with the event loop in other scenarios. For example, the disconnect method is not thread-safe and should only be used in the WebSocket thread. However, situations like server shutdown or test
cleanup require closing WebSockets from outside the event loop thread.
This PR enhances communication with the WebSocket event loop:
socketpair
is replaced by a pollable queue that allows controlling the WebSocket instances from outside of the event loop.CLOSE
andDISPATCH
. This approach allows for the future addition of more commands.disconnect
method is removed from the public API: This method is not thread-safe and should only be called from internal code running in the WebSocket thread.close
method to the public API, which relies on the command queue to properly order disconnections from outside the WebSocket thread.2. Enable WebSocket during tours
During Python tests, only one cursor is used. RPCs and WebSocket use the
TestCursor
wrapper, which relies on a lock to prevent race conditions. WebSocket connections can be opened during tours, provided they are properly cleaned up afterward to avoid conflicts with the test cursor, which is not subject to any locking.This PR adapts the
Websocket
andHttpCase
classes to enable WebSockets during tours.enterprise: https://github.com/odoo/enterprise/pull/75984