Skip to content

Commit

Permalink
[test] ota/min_max_app_size: events are a bit weird, make sure to res…
Browse files Browse the repository at this point in the history
…tart ad-hoc flash attempt if device disconnects
  • Loading branch information
avtolstoy committed Jun 28, 2024
1 parent 9abfb7c commit 8ec558e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void waitOta() {
System.enableReset();
});

for (auto start = millis(); millis() - start <= 5 * 60 * 1000;) {
for (auto start = millis(); millis() - start <= 20 * 60 * 1000;) {
if (updateResult == firmware_update_complete || updateResult == firmware_update_failed || updateResult == firmware_update_pending) {
break;
} else if (updateResult == SYSTEM_ERROR_OTA && millis() - start >= 1 * 60 * 1000) {
Expand All @@ -61,6 +61,11 @@ void waitOta() {
delay(100);
}

if (Particle.connected() && updateResult == firmware_update_complete) {
// Just in case
Particle.publish("test/ota", "success", WITH_ACK).wait();
}

assertNotEqual((int)updateResult, (int)firmware_update_failed);
assertNotEqual((int)updateResult, (int)SYSTEM_ERROR_OTA);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ async function waitFlashStatusEvent(ctx, timeout) {
if (t <= 0) {
throw new Error("Event timeout");
}
data = await ctx.particle.receiveEvent('spark/flash/status', { timeout: t });
ctx.particle.log.verbose('spark/flash/status:', data);
if (data.startsWith('success')) {
return true;
data = null;
try {
data = await Promise.race([
ctx.particle.receiveEvent('spark/flash/status', { timeout: t }),
ctx.particle.receiveEvent('test/ota', { timeout: t }),
ctx.particle.receiveEvent('spark/status', { timeout: t })
]);
} catch (err) {

}
if (data.startsWith('failed')) {
return false;
if (data) {
ctx.particle.log.verbose('(spark/runner)/flash/status:', data);
if (data.startsWith('success')) {
return true;
}
if (data.startsWith('failed')) {
return false;
}
if (data.startsWith('offline') || data.startsWith('online')) {
return false;
}
}
}
}
Expand Down

0 comments on commit 8ec558e

Please sign in to comment.