mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-11-23 12:57:58 +00:00
Field log 2026-11-10: with the screen off the Android WebView stopped running JavaScript timers while Bluetooth frames and GPS fixes kept arriving. For eleven minutes receptions were queued but nothing was published, no RF sample was taken, no discover, region ask or uplink ping went out, and the broker dropped the link for want of a keepalive. The 116-record backlog went out when the screen came back on; positions and rx_at in client_rx_observations were correct. Every frame and GPS fix now calls catchUp, which runs the jobs whose timer is overdue: the monitor tick, the drain, the pending RF sample and, when the drain is late and the broker link is down, one reconnect per 15 s. src/catchup.js holds the decision (test/catchup.test.mjs). The debug log now records when the app is hidden and visible again. Not yet tested on the phone.
40 lines
2.1 KiB
JavaScript
40 lines
2.1 KiB
JavaScript
// Timer catch-up driven by frames and GPS fixes (src/catchup.js).
|
|
// Run: node --test
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert';
|
|
import { catchUpPlan, CATCHUP } from '../src/catchup.js';
|
|
|
|
const base = { now: 100000, lastTickAt: 99500, lastDrainAt: 98000, rfDueAt: 120000, publisherDown: false, lastKickAt: null };
|
|
const none = { tick: false, drain: false, rf: false, reconnect: false };
|
|
|
|
test('nothing to do while the timers keep time', () => {
|
|
assert.deepStrictEqual(catchUpPlan(base), none);
|
|
});
|
|
|
|
test('a timer that is only a little late is left to fire itself', () => {
|
|
const s = { ...base, lastTickAt: base.now - CATCHUP.tickMs - CATCHUP.slackMs + 1, lastDrainAt: base.now - CATCHUP.drainMs - CATCHUP.slackMs + 1, rfDueAt: base.now - CATCHUP.slackMs + 1 };
|
|
assert.deepStrictEqual(catchUpPlan(s), none);
|
|
});
|
|
|
|
test('frozen timers: tick, drain and the RF sample all run from the event', () => {
|
|
const s = { ...base, lastTickAt: base.now - 600000, lastDrainAt: base.now - 600000, rfDueAt: base.now - 300000 };
|
|
assert.deepStrictEqual(catchUpPlan(s), { tick: true, drain: true, rf: true, reconnect: false });
|
|
});
|
|
|
|
test('jobs that never ran or have nothing scheduled are not caught up', () => {
|
|
assert.deepStrictEqual(catchUpPlan({ ...base, lastTickAt: null, lastDrainAt: null, rfDueAt: null }), none);
|
|
});
|
|
|
|
test('a dead broker link is reopened only when the drain timer is late too', () => {
|
|
assert.strictEqual(catchUpPlan({ ...base, publisherDown: true }).reconnect, false);
|
|
const frozen = { ...base, lastDrainAt: base.now - 60000, publisherDown: true };
|
|
assert.strictEqual(catchUpPlan(frozen).reconnect, true);
|
|
assert.strictEqual(catchUpPlan({ ...frozen, publisherDown: false }).reconnect, false);
|
|
});
|
|
|
|
test('forced reconnects are spaced at least kickMs apart', () => {
|
|
const frozen = { ...base, lastDrainAt: base.now - 60000, publisherDown: true };
|
|
assert.strictEqual(catchUpPlan({ ...frozen, lastKickAt: base.now - CATCHUP.kickMs + 1 }).reconnect, false);
|
|
assert.strictEqual(catchUpPlan({ ...frozen, lastKickAt: base.now - CATCHUP.kickMs }).reconnect, true);
|
|
});
|