test(pi): hold packaged rpc confirmation past timeout
This commit is contained in:
@@ -78,6 +78,7 @@ export class PiRpcClient {
|
||||
private readonly pending = new Map<string, PendingRequest>();
|
||||
private readonly retiredIds = new Set<string>();
|
||||
private readonly listeners = new Set<(event: PiRpcEvent) => void>();
|
||||
private readonly proofResponseDelays = new Map<string, number>();
|
||||
private sequence = 0;
|
||||
private invalidated: PiProcessError | null = null;
|
||||
|
||||
@@ -111,6 +112,13 @@ export class PiRpcClient {
|
||||
return () => this.listeners.delete(listener);
|
||||
}
|
||||
|
||||
delayNextResponseForProof(commandType: string, delayMs: number): void {
|
||||
if (!commandType || !Number.isSafeInteger(delayMs) || delayMs <= 0) {
|
||||
throw new Error('Proof response delay requires a command type and positive safe delay');
|
||||
}
|
||||
this.proofResponseDelays.set(commandType, delayMs);
|
||||
}
|
||||
|
||||
async request<T = unknown>(
|
||||
command: PiRpcCommand,
|
||||
options: PiRpcRequestOptions = {},
|
||||
@@ -161,6 +169,22 @@ export class PiRpcClient {
|
||||
if (!pending) {
|
||||
throw new PiProcessError('PI_RPC_PROTOCOL_ERROR', `Pi RPC response used unknown id ${value.id}`);
|
||||
}
|
||||
const proofDelayMs = this.proofResponseDelays.get(pending.commandType);
|
||||
if (proofDelayMs !== undefined) {
|
||||
this.proofResponseDelays.delete(pending.commandType);
|
||||
setTimeout(() => {
|
||||
try {
|
||||
this.accept(value);
|
||||
} catch (error) {
|
||||
try {
|
||||
this.onEventListenerError?.(error);
|
||||
} catch {
|
||||
// Proof diagnostics must not affect transport state.
|
||||
}
|
||||
}
|
||||
}, proofDelayMs);
|
||||
return;
|
||||
}
|
||||
pending.cancel();
|
||||
this.pending.delete(value.id);
|
||||
if (value.success) {
|
||||
|
||||
Reference in New Issue
Block a user