fix: close unconfirmed displays superseded by confirmed updates
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
from test_display import submit
|
||||
|
||||
from pigway_frame_flow.display.service import DisplayService
|
||||
@@ -107,3 +108,59 @@ def test_malformed_reconciliation_does_not_abort_other_background_work(
|
||||
assert op["recovery"]["reason"] == "reconciliation_error"
|
||||
assert "private" not in str(op["recovery"])
|
||||
assert service.blocked("living-room")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", ["SYNCING", "UNKNOWN"])
|
||||
def test_later_confirmed_display_closes_earlier_syncing_attempt_without_replay(
|
||||
service, status
|
||||
):
|
||||
first = submit(service)
|
||||
service.process_one()
|
||||
assert service.operation(first)["status"] == "SYNCING"
|
||||
second = submit(service)
|
||||
service.process_one()
|
||||
driver = service.registry.get("living-room")
|
||||
uploads = driver.client.uploads
|
||||
previous_error = {"code": "WRITE_RESULT_UNKNOWN", "message": "Refresh unconfirmed"}
|
||||
if status == "UNKNOWN":
|
||||
service.update(first, status, error=previous_error)
|
||||
service.sync()
|
||||
assert service.operation(second)["status"] == "COMPLETED"
|
||||
old = service.operation(first)
|
||||
assert old["status"] == "FAILED"
|
||||
assert old["error"]["code"] == "DISPLAY_NOT_CONFIRMED"
|
||||
assert old["error"]["details"]["superseded_by_operation_id"] == second
|
||||
if status == "UNKNOWN":
|
||||
assert old["error"]["details"]["previous_error"] == previous_error
|
||||
assert driver.client.uploads == uploads
|
||||
assert not service.blocked("living-room")
|
||||
service.sync()
|
||||
assert (
|
||||
len(
|
||||
service.db.all(
|
||||
"SELECT * FROM history WHERE operation_id=? AND result='DISPLAY_NOT_CONFIRMED'",
|
||||
(first,),
|
||||
)
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
|
||||
def test_unconfirmed_later_display_does_not_close_old_attempt(service):
|
||||
first = submit(service)
|
||||
service.process_one()
|
||||
second = submit(service)
|
||||
service.process_one()
|
||||
service.recovery.close_superseded_displays()
|
||||
assert service.operation(first)["status"] == "SYNCING"
|
||||
assert service.operation(second)["status"] == "SYNCING"
|
||||
|
||||
|
||||
def test_confirmed_temporary_override_does_not_close_earlier_display(service):
|
||||
first = submit(service)
|
||||
service.process_one()
|
||||
second = submit(service, 60, True)
|
||||
service.process_one()
|
||||
service.sync()
|
||||
assert service.operation(second)["status"] == "COMPLETED"
|
||||
assert service.operation(first)["status"] == "SYNCING"
|
||||
|
||||
Reference in New Issue
Block a user