Fix main & improve cursor sync (#101)

This commit is contained in:
Andras Schmelczer 2025-08-25 17:15:52 +01:00 committed by GitHub
parent 81b81e30ff
commit a36a24effc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 926 additions and 686 deletions

View file

@ -37,7 +37,7 @@ export class MockClient implements FileSystemOperations {
fs: this,
persistence: {
load: async () => this.data,
save: async (data) => (this.data = data)
save: async (data) => void (this.data = data)
},
fetch: fetchImplementation,
webSocket: webSocketImplementation

View file

@ -25,15 +25,18 @@ export function flakyWebSocketFactory(
public set onmessage(callback: (event: MessageEvent) => void) {
super.onmessage = async (event: MessageEvent): Promise<void> => {
await this.locks.waitForLock(FlakyWebSocket.RECEIVE_KEY);
return this.locks.withLock(
FlakyWebSocket.RECEIVE_KEY,
async () => {
if (jitterScaleInSeconds > 0) {
await sleep(
Math.random() * jitterScaleInSeconds * 1000
);
}
if (jitterScaleInSeconds > 0) {
await sleep(Math.random() * jitterScaleInSeconds * 1000);
}
callback(event);
this.locks.unlock(FlakyWebSocket.RECEIVE_KEY);
callback(event);
}
);
};
}
@ -67,15 +70,13 @@ export function flakyWebSocketFactory(
data: string | ArrayBufferLike | Blob | ArrayBufferView
): Promise<void> {
// maintain message order
await this.locks.waitForLock(FlakyWebSocket.SEND_KEY);
return this.locks.withLock(FlakyWebSocket.SEND_KEY, async () => {
if (jitterScaleInSeconds > 0) {
await sleep(Math.random() * jitterScaleInSeconds * 1000);
}
if (jitterScaleInSeconds > 0) {
await sleep(Math.random() * jitterScaleInSeconds * 1000);
}
super.send(data);
this.locks.unlock(FlakyWebSocket.SEND_KEY);
super.send(data);
});
}
} as unknown as typeof WebSocket;
}