@@ -89,19 +89,19 @@ describe('CloudFetchResultHandler', () => {
8989
9090 case1: {
9191 result . pendingLinks = [ ] ;
92- result . downloadedBatches = [ ] ;
92+ result . downloadTasks = [ ] ;
9393 expect ( await result . hasMore ( ) ) . to . be . false ;
9494 }
9595
9696 case2: {
9797 result . pendingLinks = [ { } ] ; // just anything here
98- result . downloadedBatches = [ ] ;
98+ result . downloadTasks = [ ] ;
9999 expect ( await result . hasMore ( ) ) . to . be . true ;
100100 }
101101
102102 case3: {
103103 result . pendingLinks = [ ] ;
104- result . downloadedBatches = [ { } ] ; // just anything here
104+ result . downloadTasks = [ { } ] ; // just anything here
105105 expect ( await result . hasMore ( ) ) . to . be . true ;
106106 }
107107 } ) ;
@@ -134,19 +134,19 @@ describe('CloudFetchResultHandler', () => {
134134 } while ( await rowSetProvider . hasMore ( ) ) ;
135135
136136 expect ( result . pendingLinks . length ) . to . be . equal ( expectedLinksCount ) ;
137- expect ( result . downloadedBatches . length ) . to . be . equal ( 0 ) ;
137+ expect ( result . downloadTasks . length ) . to . be . equal ( 0 ) ;
138138 expect ( result . fetch . called ) . to . be . false ;
139139 } ) ;
140140
141141 it ( 'should download batches according to settings' , async ( ) => {
142142 const clientConfig = DBSQLClient . getDefaultConfig ( ) ;
143- clientConfig . cloudFetchConcurrentDownloads = 2 ;
143+ clientConfig . cloudFetchConcurrentDownloads = 3 ;
144144
145145 const rowSet = {
146146 startRowOffset : 0 ,
147147 resultLinks : [ ...sampleRowSet1 . resultLinks , ...sampleRowSet2 . resultLinks ] ,
148148 } ;
149- const expectedLinksCount = rowSet . resultLinks . length ;
149+ const expectedLinksCount = rowSet . resultLinks . length ; // 5
150150 const rowSetProvider = new ResultsProviderMock ( [ rowSet ] ) ;
151151 const context = {
152152 getConfig : ( ) => clientConfig ,
@@ -166,24 +166,28 @@ describe('CloudFetchResultHandler', () => {
166166 expect ( await rowSetProvider . hasMore ( ) ) . to . be . true ;
167167
168168 initialFetch: {
169+ // `cloudFetchConcurrentDownloads` out of `expectedLinksCount` links should be scheduled immediately
170+ // first one should be `await`-ed and returned from `fetchNext`
169171 const items = await result . fetchNext ( { limit : 10000 } ) ;
170172 expect ( items . length ) . to . be . gt ( 0 ) ;
171173 expect ( await rowSetProvider . hasMore ( ) ) . to . be . false ;
172174
173175 expect ( result . fetch . callCount ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads ) ;
174176 expect ( result . pendingLinks . length ) . to . be . equal ( expectedLinksCount - clientConfig . cloudFetchConcurrentDownloads ) ;
175- expect ( result . downloadedBatches . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 1 ) ;
177+ expect ( result . downloadTasks . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 1 ) ;
176178 }
177179
178180 secondFetch: {
179- // It should return previously fetched batch, not performing additional network requests
181+ // It should return previously fetched batch, and schedule one more
180182 const items = await result . fetchNext ( { limit : 10000 } ) ;
181183 expect ( items . length ) . to . be . gt ( 0 ) ;
182184 expect ( await rowSetProvider . hasMore ( ) ) . to . be . false ;
183185
184- expect ( result . fetch . callCount ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads ) ; // no new fetches
185- expect ( result . pendingLinks . length ) . to . be . equal ( expectedLinksCount - clientConfig . cloudFetchConcurrentDownloads ) ;
186- expect ( result . downloadedBatches . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 2 ) ;
186+ expect ( result . fetch . callCount ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads + 1 ) ;
187+ expect ( result . pendingLinks . length ) . to . be . equal (
188+ expectedLinksCount - clientConfig . cloudFetchConcurrentDownloads - 1 ,
189+ ) ;
190+ expect ( result . downloadTasks . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 1 ) ;
187191 }
188192
189193 thirdFetch: {
@@ -192,11 +196,11 @@ describe('CloudFetchResultHandler', () => {
192196 expect ( items . length ) . to . be . gt ( 0 ) ;
193197 expect ( await rowSetProvider . hasMore ( ) ) . to . be . false ;
194198
195- expect ( result . fetch . callCount ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads * 2 ) ;
199+ expect ( result . fetch . callCount ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads + 2 ) ;
196200 expect ( result . pendingLinks . length ) . to . be . equal (
197- expectedLinksCount - clientConfig . cloudFetchConcurrentDownloads * 2 ,
201+ expectedLinksCount - clientConfig . cloudFetchConcurrentDownloads - 2 ,
198202 ) ;
199- expect ( result . downloadedBatches . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 1 ) ;
203+ expect ( result . downloadTasks . length ) . to . be . equal ( clientConfig . cloudFetchConcurrentDownloads - 1 ) ;
200204 }
201205 } ) ;
202206
@@ -251,6 +255,10 @@ describe('CloudFetchResultHandler', () => {
251255 } ) ,
252256 ) ;
253257
258+ // There are two link in the batch - first one is valid and second one is expired
259+ // The first fetch has to be successful, and the second one should fail
260+ await result . fetchNext ( { limit : 10000 } ) ;
261+
254262 try {
255263 await result . fetchNext ( { limit : 10000 } ) ;
256264 expect . fail ( 'It should throw an error' ) ;
0 commit comments