@@ -219,25 +219,54 @@ describe("CloudflareDurableObjects", () => {
219219 assert . deepStrictEqual ( result , { firstStatus : "pending" , secondStatus : "rejected" } )
220220 } ) , 60_000 )
221221
222- it . effect ( "does not run a future row when an immediate request deduplicates to it" , ( ) =>
222+ it . effect (
223+ "rejects an ask deduplicated onto a future tell without hanging or running it early" ,
224+ ( ) =>
225+ Effect . gen ( function * ( ) {
226+ const miniflare = yield * makeMiniflare
227+ const fetchJson = ( path : string ) =>
228+ Effect . promise ( ( ) =>
229+ Promise . race ( [
230+ miniflare . dispatchFetch ( `http://placeholder${ path } ` ) . then ( async ( response ) => {
231+ const body = await response . text ( )
232+ assert . strictEqual ( response . status , 200 , body )
233+ return JSON . parse ( body )
234+ } ) ,
235+ new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( `${ path } did not return` ) ) , 2_000 ) )
236+ ] )
237+ )
238+ const id = "scheduled-dedup"
239+ yield * fetchJson (
240+ `/delayed?id=${ id } &operationId=same&discard=true&deliverAt=${ Date . now ( ) + 60_000 } `
241+ )
242+ const duplicate = yield * fetchJson ( `/mailbox?id=${ id } &tag=Add&operationId=same&discard=false` )
243+ assert . strictEqual ( duplicate . error , "AskDeduplicatedToTell" )
244+
245+ const result = yield * fetchJson ( `/mailbox?id=${ id } &tag=Get` )
246+ assert . deepStrictEqual ( JSON . parse ( result . replies [ 0 ] ) . exit , { _tag : "Success" , value : 0 } )
247+ } ) ,
248+ 60_000
249+ )
250+
251+ it . effect ( "rejects an ask deduplicated onto a processed tell without hanging" , ( ) =>
223252 Effect . gen ( function * ( ) {
224253 const miniflare = yield * makeMiniflare
225254 const fetchJson = ( path : string ) =>
226255 Effect . promise ( ( ) =>
227- miniflare . dispatchFetch ( `http://placeholder${ path } ` ) . then ( async ( response ) => {
228- const body = await response . text ( )
229- assert . strictEqual ( response . status , 200 , body )
230- return JSON . parse ( body )
231- } )
256+ Promise . race ( [
257+ miniflare . dispatchFetch ( `http://placeholder${ path } ` ) . then ( async ( response ) => {
258+ const body = await response . text ( )
259+ assert . strictEqual ( response . status , 200 , body )
260+ return JSON . parse ( body )
261+ } ) ,
262+ new Promise < never > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( `${ path } did not return` ) ) , 2_000 ) )
263+ ] )
232264 )
233- const id = "scheduled-dedup"
234- yield * fetchJson (
235- `/delayed?id=${ id } &operationId=same&discard=true&deliverAt=${ Date . now ( ) + 60_000 } `
236- )
265+ const id = "processed-tell-dedup"
237266 yield * fetchJson ( `/mailbox?id=${ id } &tag=Add&operationId=same` )
267+ const duplicate = yield * fetchJson ( `/mailbox?id=${ id } &tag=Add&operationId=same&discard=false` )
238268
239- const result = yield * fetchJson ( `/mailbox?id=${ id } &tag=Get` )
240- assert . deepStrictEqual ( JSON . parse ( result . replies [ 0 ] ) . exit , { _tag : "Success" , value : 0 } )
269+ assert . strictEqual ( duplicate . error , "AskDeduplicatedToTell" )
241270 } ) , 60_000 )
242271
243272 it . effect ( "delivers a scheduled ask reply to the caller Durable Object" , ( ) =>
0 commit comments