Content-Length: 334537 | pFad | https://github.com/odoo/odoo/pull/189859

C6 [IMP] bus: enable websocket during tours by tsm-odoo · Pull Request #189859 · odoo/odoo · GitHub
Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tsm-odoo
Copy link
Contributor

@tsm-odoo tsm-odoo commented Dec 6, 2024

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:

  • 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.

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 and HttpCase classes to enable WebSockets during tours.

enterprise: https://github.com/odoo/enterprise/pull/75984

@robodoo
Copy link
Contributor

robodoo commented Dec 6, 2024

Pull request status dashboard

@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch from f0c3495 to 7772214 Compare December 6, 2024 11:59
@C3POdoo C3POdoo added the RD research & development, internal work label Dec 6, 2024
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 25 times, most recently from ddc6b7b to ea69a83 Compare December 9, 2024 11:24
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 2 times, most recently from 9dd6c11 to 94fbc8b Compare December 16, 2024 10:40
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 12 times, most recently from 8f1a17f to a5f7d5d Compare December 26, 2024 09:22
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 3 times, most recently from f734131 to 9c92bce Compare December 27, 2024 10:55
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 3 times, most recently from 383e04e to 97144da Compare January 14, 2025 09:47
odoo/tests/common.py Outdated Show resolved Hide resolved
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 3 times, most recently from df40c3a to aa3fa7e Compare January 14, 2025 11:46
addons/bus/websocket.py Outdated Show resolved Hide resolved
addons/bus/websocket.py Outdated Show resolved Hide resolved
addons/bus/websocket.py Outdated Show resolved Hide resolved
addons/bus/websocket.py Show resolved Hide resolved
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch 2 times, most recently from e09df52 to 0f03647 Compare January 14, 2025 14:34
Copy link
Member

@Julien00859 Julien00859 left a 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
@tsm-odoo tsm-odoo force-pushed the master-mail-ws_for_test-tsm branch from 0f03647 to ba18006 Compare January 15, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/odoo/odoo/pull/189859

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy