Skip to content

Commit f557142

Browse files
committed
test(remote): a proxied lease heartbeat renews the lease and keeps the session's comparison state
#2198 acceptance: lease heartbeat through the proxy. A leased session behind the proxy captures a diff baseline; an explicit lease_heartbeat RPC just before the lease's reported expiry moves the expiry forward; a request past the old expiry but inside the renewed window still finds the session and reports the baseline. Red without the renewing heartbeat (LEASE_NOT_FOUND).
1 parent 5caf2f7 commit f557142

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎test/integration/provider-scenarios/remote-proxy-parity.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,59 @@ test(
492492
},
493493
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
494494
);
495+
496+
test(
497+
'Provider-backed integration proxy lease heartbeat renews the lease and keeps the session and its comparison state',
498+
async (t) => {
499+
if (await skipWhenLoopbackUnavailable(t, 'daemon proxy parity coverage')) return;
500+
501+
let now = 2_000_000;
502+
const leaseRegistry = new LeaseRegistry({ now: () => now });
503+
await withProxiedWorld(
504+
async ({ world, proxied }) => {
505+
const session = 'renewed';
506+
const flags = { platform: 'ios', udid: SIM.id } as const;
507+
const allocated = await proxied({
508+
session,
509+
command: 'lease_allocate',
510+
positionals: [],
511+
flags: {},
512+
meta: LEASE_SCOPE,
513+
});
514+
assert.equal(allocated.ok, true, JSON.stringify(allocated));
515+
const lease = (allocated.ok ? allocated.data : {})?.lease as { leaseId: string };
516+
const meta = { ...LEASE_SCOPE, leaseId: lease.leaseId };
517+
const run = async (
518+
command: string,
519+
positionals: string[],
520+
stepFlags: DaemonRequest['flags'],
521+
) => await proxied({ session, command, positionals, flags: stepFlags, meta });
522+
523+
assert.equal((await run('open', [APP], flags)).ok, true);
524+
assert.equal((await run('snapshot', [], { snapshotInteractiveOnly: true })).ok, true);
525+
const heartbeatExpiry = async (): Promise<number> => {
526+
const heartbeat = await run('lease_heartbeat', [], {});
527+
assert.equal(heartbeat.ok, true, JSON.stringify(heartbeat));
528+
const renewed = (heartbeat.ok ? heartbeat.data : {})?.lease as { expiresAt: number };
529+
return renewed.expiresAt;
530+
};
531+
532+
// One explicit heartbeat through the proxy just before the lease would lapse moves the
533+
// expiry forward; a request past the old expiry but inside the new window still finds
534+
// the session and its diff baseline.
535+
const firstExpiry = await heartbeatExpiry();
536+
now = firstExpiry - 1_000;
537+
const renewedExpiry = await heartbeatExpiry();
538+
assert.ok(renewedExpiry > firstExpiry, 'the heartbeat moved the expiry forward');
539+
now = firstExpiry + 1_000;
540+
const diff = await run('diff', ['snapshot'], { snapshotInteractiveOnly: true });
541+
assert.equal(diff.ok, true, JSON.stringify(diff));
542+
assert.equal(baselineInitialized(diff), false, 'the renewed session kept its baseline');
543+
assert.notEqual(world.daemon.session(session), undefined);
544+
assert.equal((await run('close', [], {})).ok, true);
545+
},
546+
{ leaseRegistry },
547+
);
548+
},
549+
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
550+
);

0 commit comments

Comments
 (0)