feat(companion): expose pending request observability
This commit is contained in:
@@ -593,6 +593,44 @@ describe('CompanionRuntimeClient', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('tracks pendingRequestCount for in-flight RPCs', async () => {
|
||||
class FakeWebSocket extends EventEmitter {
|
||||
readyState: number = WebSocket.CONNECTING;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
queueMicrotask(() => {
|
||||
this.readyState = WebSocket.OPEN;
|
||||
this.emit('open');
|
||||
});
|
||||
}
|
||||
|
||||
send(_payload: string, callback?: (error?: Error) => void): void {
|
||||
callback?.();
|
||||
}
|
||||
|
||||
close(_code?: number, _reason?: string): void {
|
||||
this.readyState = WebSocket.CLOSED;
|
||||
this.emit('close');
|
||||
}
|
||||
}
|
||||
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
websocketFactory: () => new FakeWebSocket() as unknown as WebSocket,
|
||||
requestTimeoutMs: 10_000,
|
||||
});
|
||||
await client.connect();
|
||||
expect(client.pendingRequestCount).toBe(0);
|
||||
|
||||
const pending = client.call('system.capabilities');
|
||||
expect(client.pendingRequestCount).toBe(1);
|
||||
|
||||
client.disconnect();
|
||||
await expect(pending).rejects.toThrow('Disconnected');
|
||||
expect(client.pendingRequestCount).toBe(0);
|
||||
});
|
||||
|
||||
it('connects and performs node registration + capability discovery', async () => {
|
||||
if (!LISTEN_ALLOWED) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user