fix(net): validate wire frames and coalesce reconnects
This commit is contained in:
@@ -11,14 +11,16 @@ export class FakeTransport implements Transport {
|
||||
private closeCb?: () => void;
|
||||
private pending: Array<() => void> = [];
|
||||
private closed = false;
|
||||
private connectFailure: unknown = null;
|
||||
private hasConnectFailure = false;
|
||||
private connectFailure: unknown;
|
||||
|
||||
connect(url: string): void {
|
||||
this.connectCalls++;
|
||||
this.url = url;
|
||||
if (this.connectFailure !== null) {
|
||||
if (this.hasConnectFailure) {
|
||||
const error = this.connectFailure;
|
||||
this.connectFailure = null;
|
||||
this.hasConnectFailure = false;
|
||||
this.connectFailure = undefined;
|
||||
throw error;
|
||||
}
|
||||
this.pending.push(() => this.openCb?.());
|
||||
@@ -35,7 +37,10 @@ export class FakeTransport implements Transport {
|
||||
onClose(cb: () => void): void { this.closeCb = cb; }
|
||||
|
||||
/** 测试侧:令下一次 connect 同步失败。 */
|
||||
failNextConnect(error: unknown): void { this.connectFailure = error; }
|
||||
failNextConnect(error: unknown): void {
|
||||
this.hasConnectFailure = true;
|
||||
this.connectFailure = error;
|
||||
}
|
||||
|
||||
/** 测试侧:模拟服务器推一帧给客户端。 */
|
||||
serverPush(frame: string): void { this.pending.push(() => this.msgCb?.(frame)); }
|
||||
|
||||
Reference in New Issue
Block a user