mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
fix: deletes send their removal after the reply; test_reboot waits for the restart
- shadeRemoved, groupRemoved and roomRemoved went out from the deletes, before the edit's reply. They now come from editChanges and go out with the edit's other events, after it (test_adding_and_deleting_a_room). - test_reboot reconnected in the moment between the sockets closing and the restart, and waited for a hello that never came. It now waits, retries a connect without hello, and checks the uptime went back. e2e on the device (esp32s3dbg): 72 passed, 3 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
17bb571635
commit
2c815d30f1
7 changed files with 53 additions and 20 deletions
|
|
@ -118,10 +118,14 @@ def test_a_frequency_scan_starts_and_ends(connect, schema):
|
|||
def test_reboot(request, host, token, connect, schema):
|
||||
if not request.config.getoption("--reboot"):
|
||||
pytest.skip("reboots the device: pass --reboot")
|
||||
c, _, _ = synced_model(connect, schema)
|
||||
c = connect(schema=schema.hash)
|
||||
_, frames, _ = run_sync(c)
|
||||
uptime_before = uptime(schema, frames)
|
||||
assert is_ok(schema, op(c, schema, "reboot", {}))
|
||||
assert c.closed.wait(15), "the socket stayed open"
|
||||
# Back once it answers a connect with hello again.
|
||||
# The device closes its sockets just before it restarts, and may still
|
||||
# take a connection in between: that one never gets its hello.
|
||||
time.sleep(3)
|
||||
end = time.time() + 90
|
||||
while True:
|
||||
assert time.time() < end, "the device didn't come back"
|
||||
|
|
@ -132,9 +136,19 @@ def test_reboot(request, host, token, connect, schema):
|
|||
continue
|
||||
try:
|
||||
if back.status == 101:
|
||||
hello, _, _ = run_sync(back)
|
||||
hello, frames, _ = run_sync(back, timeout=10)
|
||||
assert hello["d"]["sh"] == schema.hash
|
||||
assert uptime(schema, frames) < uptime_before, "the device didn't restart"
|
||||
return
|
||||
except TimeoutError:
|
||||
pass # not back yet
|
||||
finally:
|
||||
back.close()
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def uptime(schema, frames):
|
||||
"""The uptime, in ms, from the status a sync ends with."""
|
||||
key = schema.keys["status"]
|
||||
status = next(f["d"][key] for f in frames if key in f["d"])
|
||||
return schema.expand(status)["uptime"]
|
||||
|
|
|
|||
10
test/fixtures/proto2/sync.json
vendored
10
test/fixtures/proto2/sync.json
vendored
|
|
@ -1515,13 +1515,15 @@
|
|||
}
|
||||
],
|
||||
"Z": {
|
||||
"fr": 148772,
|
||||
"fr": 148760,
|
||||
"mx": 77812,
|
||||
"mn": 99332,
|
||||
"mn": 102424,
|
||||
"to": 294616,
|
||||
"up": 24633,
|
||||
"up": 30144,
|
||||
"lp": 2862,
|
||||
"lx": 106737,
|
||||
"sd": "ssid 72",
|
||||
"sg": -51,
|
||||
"sg": -52,
|
||||
"ch": 6
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,16 +205,30 @@ static void test_a_repeater_edit_sends_the_repeaters() {
|
|||
TEST_ASSERT_TRUE(editChanges(model_edit_type_t::unlink_repeater, resultFor(0)).repeaters);
|
||||
TEST_ASSERT_FALSE(editChanges(model_edit_type_t::save_room, resultFor(1)).repeaters);
|
||||
}
|
||||
static void test_deletes_send_nothing_more() {
|
||||
// Their removals go out as they happen.
|
||||
for(model_edit_type_t t : {model_edit_type_t::delete_room, model_edit_type_t::delete_shade, model_edit_type_t::delete_group}) {
|
||||
const edit_changes_t c = editChanges(t, resultFor(4));
|
||||
static void test_deletes_send_their_removal() {
|
||||
// After the reply, as every edit's events are, so a client waiting for the
|
||||
// reply doesn't read past it.
|
||||
const edit_changes_t room = editChanges(model_edit_type_t::delete_room, resultFor(4));
|
||||
const edit_changes_t shade = editChanges(model_edit_type_t::delete_shade, resultFor(5));
|
||||
const edit_changes_t group = editChanges(model_edit_type_t::delete_group, resultFor(6));
|
||||
TEST_ASSERT_EQUAL_UINT8(4, room.removedRoomId);
|
||||
TEST_ASSERT_EQUAL_UINT8(5, shade.removedShadeId);
|
||||
TEST_ASSERT_EQUAL_UINT8(6, group.removedGroupId);
|
||||
for(const edit_changes_t &c : {room, shade, group}) {
|
||||
// Nothing is left of it to send whole.
|
||||
TEST_ASSERT_EQUAL_UINT8(0, c.shadeId);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, c.groupId);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, c.roomId);
|
||||
TEST_ASSERT_EQUAL(sort_list_t::none, c.order);
|
||||
TEST_ASSERT_FALSE(c.repeaters);
|
||||
}
|
||||
TEST_ASSERT_EQUAL_UINT8(0, room.removedShadeId + room.removedGroupId);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, shade.removedRoomId + shade.removedGroupId);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, group.removedRoomId + group.removedShadeId);
|
||||
}
|
||||
static void test_other_edits_remove_nothing() {
|
||||
const edit_changes_t c = editChanges(model_edit_type_t::save_room, resultFor(4));
|
||||
TEST_ASSERT_EQUAL_UINT8(0, c.removedRoomId + c.removedShadeId + c.removedGroupId);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
@ -249,6 +263,7 @@ int main(int argc, char **argv) {
|
|||
RUN_TEST(test_a_room_edit_sends_the_room);
|
||||
RUN_TEST(test_a_sort_edit_sends_its_list);
|
||||
RUN_TEST(test_a_repeater_edit_sends_the_repeaters);
|
||||
RUN_TEST(test_deletes_send_nothing_more);
|
||||
RUN_TEST(test_deletes_send_their_removal);
|
||||
RUN_TEST(test_other_edits_remove_nothing);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue