Port Value Management Updates - #215
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates qToggleServer’s port value-writing pipeline by introducing an explicit write queue (with optional completion futures), adding clearer “target value” semantics for expression-driven writes, and adjusting the HTTP API write endpoint to route writes through the queue rather than writing directly.
Changes:
- Add
WriteRequest+ queued write helpers (push_write,push_write_and_wait) and useget_target_value()to avoid redundant queued writes. - Switch port sequences to enqueue writes (instead of fire-and-forget direct writes) and extend
Sequenceto support forwarding extra callback args/kwargs. - Remove the
APIAccepted(202) pathway and updatepatch_port_valueto wait for queued writes to complete.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/qtoggleserver/utils/test_sequence.py |
Adds unit tests for Sequence behavior, including callback argument forwarding and cancellation/repeat behavior. |
tests/unit/qtoggleserver/core/test_ports.py |
Adds/updates tests for new target-value logic, queued writes, persistence write_queue, and legacy persisted value behavior. |
tests/unit/qtoggleserver/core/api/test_funcs_ports.py |
Adds tests ensuring PATCH /ports/{id}/value routes through push_write_and_wait and maps write errors to API errors. |
qtoggleserver/web/base.py |
Removes web-layer handling for the removed APIAccepted exception. |
qtoggleserver/utils/sequence.py |
Extends Sequence to forward callback args/kwargs to its callback. |
qtoggleserver/core/ports.py |
Introduces WriteRequest, write queue semantics, get_target_value(), persistence format change to write_queue, and sequence writes via queue. |
qtoggleserver/core/api/funcs/ports.py |
Updates patch_port_value to queue + wait for writes instead of calling transform_and_write_value directly. |
Suppressed comments (2)
tests/unit/qtoggleserver/core/test_ports.py:174
- Same
asyncio.get_event_loop().create_future()concern here: inside an async test it should useasyncio.get_running_loop()to avoid deprecation/behavior changes on Python >= 3.14.
mocker.patch.object(mock_num_port1, "transform_and_write_value", new=blocking_transform)
future_a = asyncio.get_event_loop().create_future()
future_b = asyncio.get_event_loop().create_future()
mock_num_port1.push_write(1, future=future_a)
mock_num_port1.push_write(2, future=future_b)
tests/unit/qtoggleserver/core/test_ports.py:121
- This test also uses
asyncio.get_event_loop().create_future(). Since tests are running on Python >= 3.14, preferasyncio.get_running_loop().create_future()inside async tests.
mocker.patch.object(mock_num_port1, "save_asap")
mock_num_port1._write_queue.clear()
evicted_future = asyncio.get_event_loop().create_future()
mock_num_port1.push_write(1, future=evicted_future)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.