@@ -303,7 +303,7 @@ describeRepeats('resends', () => {
303303 } )
304304
305305 describe ( 'resendSubscribe' , ( ) => {
306- it . only ( 'sees resends and realtime' , async ( ) => {
306+ it ( 'sees resends and realtime' , async ( ) => {
307307 client . debug ( 'sees resends and realtime >' )
308308 const sub = await subscriber . resendSubscribe ( {
309309 streamId : stream . id ,
@@ -349,48 +349,7 @@ describeRepeats('resends', () => {
349349 client . debug ( 'sees resends and realtime <' )
350350 } )
351351
352- it . only ( 'sees resends and realtime again' , async ( ) => {
353- client . debug ( 'sees resends and realtime again >' )
354- const sub = await subscriber . resendSubscribe ( {
355- streamId : stream . id ,
356- last : published . length ,
357- } )
358-
359- const onResent = jest . fn ( )
360- sub . on ( 'resent' , onResent )
361-
362- const message = Msg ( )
363- // eslint-disable-next-line no-await-in-loop
364- client . debug ( 'PUBLISH >' )
365- const req = await client . publish ( stream . id , message , 333333 ) // should be realtime
366- client . debug ( 'PUBLISH <' )
367- published . push ( message )
368- publishedRequests . push ( req )
369- client . debug ( 'COLLECT >' )
370- const receivedMsgs = await collect ( sub , async ( { received } ) => {
371- client . debug ( {
372- received : received . length ,
373- published : published . length
374- } )
375- if ( received . length === published . length ) {
376- await sub . return ( )
377- }
378- } )
379- client . debug ( 'COLLECT <' )
380-
381- const msgs = receivedMsgs
382- expect ( msgs ) . toHaveLength ( published . length )
383- expect ( msgs ) . toEqual ( published )
384- expect ( subscriber . count ( stream . id ) ) . toBe ( 0 )
385- expect ( sub . realtime . isReadable ( ) ) . toBe ( false )
386- expect ( sub . realtime . isWritable ( ) ) . toBe ( false )
387- expect ( sub . resend . isReadable ( ) ) . toBe ( false )
388- expect ( sub . resend . isWritable ( ) ) . toBe ( false )
389- expect ( onResent ) . toHaveBeenCalledTimes ( 1 )
390- client . debug ( 'sees resends and realtime again <' )
391- } )
392-
393- it . only ( 'sees resends when no realtime' , async ( ) => {
352+ it ( 'sees resends when no realtime' , async ( ) => {
394353 client . debug ( 'sees resends when no realtime >' )
395354 const sub = await subscriber . resendSubscribe ( {
396355 streamId : stream . id ,
@@ -542,4 +501,70 @@ describeRepeats('resends', () => {
542501 } )
543502 } )
544503 } )
504+
505+ it . only ( 'sequential resendSubscribe' , async ( ) => {
506+ await client . connect ( )
507+ const results = await publishTestMessages . raw ( MAX_MESSAGES , {
508+ waitForLast : true ,
509+ timestamp : 111111 ,
510+ } )
511+
512+ published = results . map ( ( [ msg ] : any ) => msg )
513+ publishedRequests = results . map ( ( [ , req ] : any ) => req )
514+
515+ async function waitForLastMessage ( ) {
516+ await client . connect ( )
517+ // ensure last message is in storage
518+ const lastRequest = publishedRequests [ publishedRequests . length - 1 ]
519+ await waitForStorage ( lastRequest )
520+ client . debug ( 'was stored' , lastRequest )
521+ }
522+
523+ async function check ( id : number ) {
524+ const debug = client . debug . extend ( `check ${ id } ` )
525+ debug ( 'check >' )
526+ const sub = await subscriber . resendSubscribe ( {
527+ streamId : stream . id ,
528+ last : published . length ,
529+ } )
530+
531+ const onResent = jest . fn ( )
532+ sub . on ( 'resent' , onResent )
533+
534+ const message = Msg ( )
535+ // eslint-disable-next-line no-await-in-loop
536+ debug ( 'PUBLISH >' )
537+ const req = await client . publish ( stream . id , message , id ) // should be realtime
538+ debug ( 'PUBLISH <' )
539+ published . push ( message )
540+ publishedRequests . push ( req )
541+ debug ( 'COLLECT >' )
542+ const receivedMsgs = await collect ( sub , async ( { received } ) => {
543+ if ( received . length === published . length ) {
544+ await sub . return ( )
545+ }
546+ } )
547+ debug ( 'COLLECT <' )
548+
549+ const msgs = receivedMsgs
550+ expect ( msgs ) . toHaveLength ( published . length )
551+ expect ( msgs ) . toEqual ( published )
552+ client . debug ( 'check <' )
553+ }
554+
555+ await client . connect ( )
556+ await check ( 111111 )
557+ await waitForLastMessage ( )
558+ await client . disconnect ( )
559+
560+ await client . connect ( )
561+ await check ( 222222 )
562+ await waitForLastMessage ( )
563+ await client . disconnect ( )
564+
565+ await client . connect ( )
566+ await check ( 333333 )
567+ await waitForLastMessage ( )
568+ await client . disconnect ( )
569+ } , 60000 )
545570} )
0 commit comments