(
id: string,
onConnect: () => void,
)
| 1163 | // holding a dead handle. The cache must drop the handle on the |
| 1164 | // way out so the next operation reconnects. |
| 1165 | function transportFailingBackend( |
| 1166 | id: string, |
| 1167 | onConnect: () => void, |
| 1168 | ): { backend: WorkspaceBackend; failNext: () => void } { |
| 1169 | let shouldFail = false; |
| 1170 | const sync: import("@cloudflare/computer-rpc").SyncRPC = { |
| 1171 | ...fakeRpc(), |
| 1172 | async push(input) { |
| 1173 | if (shouldFail) throw new WorkspaceTransportError("WebSocket closed"); |
| 1174 | const reader = input.changes.getReader(); |
| 1175 | try { |
| 1176 | while (true) { |
| 1177 | const { done } = await reader.read(); |
| 1178 | if (done) break; |
| 1179 | } |
| 1180 | } finally { |
| 1181 | reader.releaseLock(); |
| 1182 | } |
| 1183 | return { rev: 0, appliedPushCursor: { rev: input.senderRev, path: null } }; |
| 1184 | }, |
| 1185 | async fetchChanges() { |
| 1186 | if (shouldFail) throw new WorkspaceTransportError("WebSocket closed"); |
| 1187 | return { |
| 1188 | currentCursor: { rev: 0, path: null }, |
| 1189 | appliedPushCursor: { rev: 0, path: null }, |
| 1190 | stream: new ReadableStream<import("@cloudflare/dofs").ChangeEntry>({ |
| 1191 | start(c) { |
| 1192 | c.close(); |
| 1193 | }, |
| 1194 | }), |
| 1195 | }; |
| 1196 | }, |
| 1197 | async watermarks() { |
| 1198 | return { currentRev: 0, pushRev: 0, fetchCursor: { rev: 0, path: null } }; |
| 1199 | }, |
| 1200 | }; |
| 1201 | const backend: WorkspaceBackend = { |
| 1202 | id, |
| 1203 | type: "fake", |
| 1204 | async connect(): Promise<BackendHandle> { |
| 1205 | onConnect(); |
| 1206 | // closed promise stays pending forever — simulating a |
| 1207 | // wedged transport that never produces a clean signal. |
| 1208 | return { |
| 1209 | rpc: composite(sync), |
| 1210 | closed: new Promise<void>(() => {}), |
| 1211 | close: async () => {}, |
| 1212 | }; |
| 1213 | }, |
| 1214 | }; |
| 1215 | return { |
| 1216 | backend, |
| 1217 | failNext: () => { |
| 1218 | shouldFail = true; |
| 1219 | }, |
| 1220 | }; |
| 1221 | } |
| 1222 |
no test coverage detected