Repository navigation
Add native local backup creation #47
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
Changes from all commits
224265f
8d91777
d178851
a317e2a
736c1d3
fc12095
de4ce12
5cc58ff
c91a435
9abfb02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,14 +336,20 @@ def request(self, message, timeout=5.0): | |
| self._check_lost() # woken by _confirm_lost, not by a reply | ||
| return slot[0] | ||
|
|
||
| def collect(self, expected_class, trigger, seconds, match=None): | ||
| """Fire ``trigger()`` and gather EVERY matching message for ``seconds``. | ||
| def collect(self, expected_class, trigger, seconds, match=None, until=None): | ||
| """Fire ``trigger()`` and gather matching messages for ``seconds``. | ||
|
|
||
| The counterpart of :meth:`await_broadcast` for the case where one request | ||
| provokes many pushes rather than one: a single ``File`` READ makes the | ||
| device enumerate every folder it knows about, several hundred of them on | ||
| the observed unit, arriving over ten to twenty seconds. | ||
|
|
||
| ``until``, if supplied, is a predicate that ends collection as soon as | ||
| it accepts any newly arrived matching message. This serves finite chunk streams | ||
| whose final message marks itself; without it the collector keeps the | ||
| original fixed-window behavior and gathers every matching message until | ||
| ``seconds`` expires. | ||
|
|
||
| Returns the messages in arrival order. Unlike a waiter, a collector does | ||
| not consume messages - they still reach any waiter or other collector. | ||
|
|
||
|
|
@@ -360,7 +366,16 @@ def collect(self, expected_class, trigger, seconds, match=None): | |
| try: | ||
| trigger() | ||
| deadline = time.monotonic() + seconds | ||
| checked = 0 | ||
| while time.monotonic() < deadline: | ||
| if until is not None: | ||
| newest = got[checked:] | ||
| # Advance only by the snapshot we just inspected. The RX | ||
| # thread may append between the slice and this update; a | ||
| # fresh len(got) here would skip that arrival forever. | ||
| checked += len(newest) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This is right, and nothing holds it in place. I put the old line back and ran the whole suite. All 2741 tests still passed. So if someone later tidies this up and reaches for I am not asking you to fix that here. It is genuinely hard to test: the gap you are protecting against is between two lines that run one after the other, so catching it needs a way to make a message arrive in the middle, and there is no hook for that today. I had to use a fake list that appends to itself when it is read. Your comment above is a fair substitute, and it says the right thing. I wanted it on the record that the comment is what is guarding this, rather than a test. |
||
| if any(until(message) for message in newest): | ||
| break | ||
| if self._device_lost is not None: | ||
| break # nothing more is coming; return what arrived | ||
| time.sleep(0.1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Read-only hardware coverage for the native local-backup stream.""" | ||
| import base64 | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.verifies("create_local_backup") | ||
| def test_local_backup_is_a_complete_portable_document(qc, profile, record_property): | ||
| if "create_local_backup" not in profile.VERIFIED: | ||
| pytest.skip(f"create_local_backup is not VERIFIED on {profile.__name__}") | ||
| document = qc.create_local_backup() | ||
|
|
||
| assert document["type"] == "backup" | ||
| assert document["creator"] == "quad" | ||
| assert isinstance(document["name"], str) and document["name"] | ||
|
tony-xmelon marked this conversation as resolved.
Resolved
|
||
| assert len(document["payload_hash"]) == 64 | ||
| assert all(c in "0123456789abcdefABCDEF" for c in document["payload_hash"]) | ||
| payload = base64.b64decode(document["payload"], validate=True) | ||
| assert payload | ||
|
|
||
| record_property("local_backup_payload_bytes", len(payload)) | ||
Uh oh!
There was an error while loading. Please reload this page.