Skip to content

Commit e3fa093

Browse files
authored
Test proxying an RPC stub all the way to Durable Objects. (#122)
* Update dependencies. * Test proxying an RPC stub all the way to Durable Objects. In particular, the DO keeps a dup() of the stub and uses it later, after the original subscription call has returned. This requires the `rpc_params_dup_stubs` compat flag, which became default as of 2026-01-20, hence the compat flag update. Fixes #110.
1 parent 10abaf3 commit e3fa093

5 files changed

Lines changed: 1080 additions & 599 deletions

File tree

__tests__/test-server-workerd.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export class TestDo extends DurableObject {
3535
getValue() {
3636
return this.value;
3737
}
38+
39+
subscribe(callback) {
40+
this.subscriber = callback.dup();
41+
}
42+
43+
async notify(value) {
44+
await this.subscriber(value);
45+
this.subscriber[Symbol.dispose]();
46+
}
3847
}
3948

4049
export class TestTarget extends RpcTarget {

__tests__/workerd.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ interface Env {
230230
interface TestDo extends DurableObject {
231231
setValue(val: any): void;
232232
getValue(): any;
233+
234+
subscribe(callback: (s: string) => void): void;
235+
notify(value: string): void;
233236
}
234237

235238
interface WorkerdTestTarget extends TestTarget {
@@ -268,6 +271,18 @@ describe("workerd RPC server", () => {
268271
expect(await foo.getValue()).toBe(123);
269272
expect(await bar.getValue()).toBe("abc");
270273
}
274+
275+
{
276+
let baz = cap.getDurableObject("baz");
277+
278+
let receivedValue: any;
279+
280+
await baz.subscribe((value: any) => {receivedValue = value});
281+
282+
await baz.notify("hello");
283+
284+
expect(receivedValue).toBe("hello");
285+
}
271286
})
272287

273288
it("can accept HTTP batch RPC connections", async () => {

0 commit comments

Comments
 (0)