@@ -5,7 +5,14 @@ import { batch } from "./batch.js";
55import { createTask } from "./shared.js" ;
66import { tasks } from "./tasks.js" ;
77
8- const DEBOUNCE = { key : "warm-conn-notify" , delay : "12h" , mode : "trailing" as const } ;
8+ const debounceFor = ( i : number ) => ( {
9+ key : `warm-conn-notify:${ i } ` ,
10+ delay : "12h" ,
11+ maxDelay : "24h" ,
12+ mode : "trailing" as const ,
13+ } ) ;
14+
15+ const EXPECTED = [ debounceFor ( 0 ) , debounceFor ( 1 ) ] ;
916
1017type Payload = { i : number } ;
1118
@@ -55,11 +62,12 @@ function installBatchCapture() {
5562 } ) ;
5663 }
5764
58- return Response . json ( { } ) ;
65+ throw new Error ( `Unexpected request during batch trigger: ${ url } ` ) ;
5966 } ) as typeof fetch ;
6067
6168 return {
62- debounceOptions : ( ) => sent . sort ( ( a , b ) => a . index - b . index ) . map ( ( i ) => i . options ?. debounce ) ,
69+ debounceOptions : ( ) =>
70+ [ ...sent ] . sort ( ( a , b ) => a . index - b . index ) . map ( ( item ) => item . options ?. debounce ) ,
6371 restore : ( ) => {
6472 globalThis . fetch = originalFetch ;
6573 } ,
@@ -93,61 +101,61 @@ describe("batch trigger debounce forwarding", () => {
93101 name : "task.batchTrigger(array)" ,
94102 call : ( ) =>
95103 taskA . batchTrigger ( [
96- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
97- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
104+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
105+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
98106 ] ) ,
99107 } ,
100108 {
101109 name : "task.batchTrigger(asyncIterable)" ,
102110 call : ( ) =>
103111 taskA . batchTrigger (
104112 asAsyncIterable ( [
105- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
106- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
113+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
114+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
107115 ] )
108116 ) ,
109117 } ,
110118 {
111119 name : "tasks.batchTrigger(array)" ,
112120 call : ( ) =>
113121 tasks . batchTrigger < typeof taskA > ( "task-a" , [
114- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
115- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
122+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
123+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
116124 ] ) ,
117125 } ,
118126 {
119127 name : "batch.trigger(array)" ,
120128 call : ( ) =>
121129 batch . trigger < typeof taskA | typeof taskB > ( [
122- { id : "task-a" , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
123- { id : "task-b" , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
130+ { id : "task-a" , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
131+ { id : "task-b" , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
124132 ] ) ,
125133 } ,
126134 {
127135 name : "batch.trigger(asyncIterable)" ,
128136 call : ( ) =>
129137 batch . trigger < typeof taskA | typeof taskB > (
130138 asAsyncIterable ( [
131- { id : "task-a" as const , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
132- { id : "task-b" as const , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
139+ { id : "task-a" as const , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
140+ { id : "task-b" as const , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
133141 ] )
134142 ) ,
135143 } ,
136144 {
137145 name : "batch.triggerByTask(array)" ,
138146 call : ( ) =>
139147 batch . triggerByTask ( [
140- { task : taskA , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
141- { task : taskB , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
148+ { task : taskA , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
149+ { task : taskB , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
142150 ] ) ,
143151 } ,
144152 {
145153 name : "batch.triggerByTask(asyncIterable)" ,
146154 call : ( ) =>
147155 batch . triggerByTask (
148156 asAsyncIterable ( [
149- { task : taskA , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
150- { task : taskB , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
157+ { task : taskA , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
158+ { task : taskB , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
151159 ] )
152160 ) ,
153161 } ,
@@ -156,69 +164,69 @@ describe("batch trigger debounce forwarding", () => {
156164 it . each ( surfaces ) ( "$name forwards debounce for every item" , async ( { call } ) => {
157165 await call ( ) ;
158166
159- expect ( capture . debounceOptions ( ) ) . toEqual ( [ DEBOUNCE , DEBOUNCE ] ) ;
167+ expect ( capture . debounceOptions ( ) ) . toEqual ( EXPECTED ) ;
160168 } ) ;
161169
162170 const waitSurfaces : Array < { name : string ; call : ( ) => Promise < unknown > } > = [
163171 {
164172 name : "task.batchTriggerAndWait(array)" ,
165173 call : ( ) =>
166174 taskA . batchTriggerAndWait ( [
167- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
168- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
175+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
176+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
169177 ] ) ,
170178 } ,
171179 {
172180 name : "task.batchTriggerAndWait(asyncIterable)" ,
173181 call : ( ) =>
174182 taskA . batchTriggerAndWait (
175183 asAsyncIterable ( [
176- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
177- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
184+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
185+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
178186 ] )
179187 ) ,
180188 } ,
181189 {
182190 name : "tasks.batchTriggerAndWait(array)" ,
183191 call : ( ) =>
184192 tasks . batchTriggerAndWait < typeof taskA > ( "task-a" , [
185- { payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
186- { payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
193+ { payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
194+ { payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
187195 ] ) ,
188196 } ,
189197 {
190198 name : "batch.triggerAndWait(array)" ,
191199 call : ( ) =>
192200 batch . triggerAndWait < typeof taskA | typeof taskB > ( [
193- { id : "task-a" , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
194- { id : "task-b" , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
201+ { id : "task-a" , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
202+ { id : "task-b" , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
195203 ] ) ,
196204 } ,
197205 {
198206 name : "batch.triggerAndWait(asyncIterable)" ,
199207 call : ( ) =>
200208 batch . triggerAndWait < typeof taskA | typeof taskB > (
201209 asAsyncIterable ( [
202- { id : "task-a" as const , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
203- { id : "task-b" as const , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
210+ { id : "task-a" as const , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
211+ { id : "task-b" as const , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
204212 ] )
205213 ) ,
206214 } ,
207215 {
208216 name : "batch.triggerByTaskAndWait(array)" ,
209217 call : ( ) =>
210218 batch . triggerByTaskAndWait ( [
211- { task : taskA , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
212- { task : taskB , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
219+ { task : taskA , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
220+ { task : taskB , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
213221 ] ) ,
214222 } ,
215223 {
216224 name : "batch.triggerByTaskAndWait(asyncIterable)" ,
217225 call : ( ) =>
218226 batch . triggerByTaskAndWait (
219227 asAsyncIterable ( [
220- { task : taskA , payload : { i : 0 } , options : { debounce : DEBOUNCE } } ,
221- { task : taskB , payload : { i : 1 } , options : { debounce : DEBOUNCE } } ,
228+ { task : taskA , payload : { i : 0 } , options : { debounce : debounceFor ( 0 ) } } ,
229+ { task : taskB , payload : { i : 1 } , options : { debounce : debounceFor ( 1 ) } } ,
222230 ] )
223231 ) ,
224232 } ,
@@ -229,6 +237,6 @@ describe("batch trigger debounce forwarding", () => {
229237 await call ( ) ;
230238 } ) ;
231239
232- expect ( capture . debounceOptions ( ) ) . toEqual ( [ DEBOUNCE , DEBOUNCE ] ) ;
240+ expect ( capture . debounceOptions ( ) ) . toEqual ( EXPECTED ) ;
233241 } ) ;
234242} ) ;
0 commit comments