@@ -20,18 +20,21 @@ import { Subscriber } from '../../src/subscribe'
2020
2121const WAIT_FOR_STORAGE_TIMEOUT = process . env . CI ? 12000 : 6000
2222const MAX_MESSAGES = 5
23- const ITERATIONS = 3
23+ const ITERATIONS = 6
2424
2525describeRepeats ( 'sequential resend subscribe' , ( ) => {
2626 let expectErrors = 0 // check no errors by default
2727 let onError = jest . fn ( )
28+
2829 let client : StreamrClient
30+ let subscriber : Subscriber
2931 let stream : Stream
30- let published : any [ ]
31- let publishedRequests : any [ ]
32+
3233 let publishTestMessages : ReturnType < typeof getPublishTestMessages >
3334 let waitForStorage : ( ...args : any [ ] ) => Promise < void >
34- let subscriber : Subscriber
35+
36+ let published : any [ ] // keeps track of stream message data so we can verify they were resent
37+ let publishedRequests : any [ ] // tracks publish requests so we can pass them to waitForStorage
3538
3639 const createClient = ( opts = { } ) => {
3740 const c = new StreamrClient ( {
@@ -77,6 +80,8 @@ describeRepeats('sequential resend subscribe', () => {
7780 } )
7881
7982 await client . connect ( )
83+ // initialize resend data by publishing some messages and waiting for
84+ // them to land in storage
8085 const results = await publishTestMessages . raw ( MAX_MESSAGES , {
8186 waitForLast : true ,
8287 timestamp : 111111 ,
@@ -92,6 +97,14 @@ describeRepeats('sequential resend subscribe', () => {
9297 onError = jest . fn ( )
9398 } )
9499
100+ afterEach ( async ( ) => {
101+ await client . connect ( )
102+ // ensure last message is in storage
103+ const lastRequest = publishedRequests [ publishedRequests . length - 1 ]
104+ await waitForStorage ( lastRequest )
105+ client . debug ( 'was stored' , lastRequest )
106+ } )
107+
95108 afterEach ( async ( ) => {
96109 await wait ( 0 )
97110 // ensure no unexpected errors
@@ -101,14 +114,6 @@ describeRepeats('sequential resend subscribe', () => {
101114 }
102115 } )
103116
104- afterEach ( async ( ) => {
105- await client . connect ( )
106- // ensure last message is in storage
107- const lastRequest = publishedRequests [ publishedRequests . length - 1 ]
108- await waitForStorage ( lastRequest )
109- client . debug ( 'was stored' , lastRequest )
110- } )
111-
112117 afterEach ( async ( ) => {
113118 if ( client ) {
114119 client . debug ( 'disconnecting after test' )
@@ -124,7 +129,11 @@ describeRepeats('sequential resend subscribe', () => {
124129 } )
125130
126131 for ( let i = 0 ; i < ITERATIONS ; i ++ ) {
127- const id = ( i + 1 ) * 111111
132+ // keep track of which messages were published in previous tests
133+ // so we can check that they exist in resends of subsequent tests
134+ // publish messages with timestamps like 222222, 333333, etc so the
135+ // sequencing is clearly visible in logs
136+ const id = ( i + 2 ) * 111111 // start at 222222
128137 // eslint-disable-next-line no-loop-func
129138 test ( `test ${ id } ` , async ( ) => {
130139 const debug = client . debug . extend ( `check ${ id } ` )
@@ -142,6 +151,7 @@ describeRepeats('sequential resend subscribe', () => {
142151 debug ( 'PUBLISH >' )
143152 const req = await client . publish ( stream . id , message , id ) // should be realtime
144153 debug ( 'PUBLISH <' )
154+ // keep track of published messages so we can check they are resent in next test(s)
145155 published . push ( message )
146156 publishedRequests . push ( req )
147157 debug ( 'COLLECT >' )
@@ -156,6 +166,6 @@ describeRepeats('sequential resend subscribe', () => {
156166 expect ( msgs ) . toHaveLength ( published . length )
157167 expect ( msgs ) . toEqual ( published )
158168 client . debug ( 'check <' )
159- } , 30000 )
169+ } )
160170 }
161171} )
0 commit comments