@@ -30,6 +30,7 @@ import {
30
30
import FtpHandler from "../FtpHandler" ;
31
31
import AuthorizedRegistryClient from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient" ;
32
32
import parseUriSafe from "../parseUriSafe" ;
33
+ import RandomStream from "./RandomStream" ;
33
34
34
35
describe ( "onRecordFound" , function ( this : Mocha . ISuiteCallbackContext ) {
35
36
this . timeout ( 20000 ) ;
@@ -141,11 +142,16 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
141
142
return jsc . assert (
142
143
jsc . forall ( recordArbWithSuccesses , function ( {
143
144
record,
144
- successLookup,
145
- disallowHead
145
+ successLookup
146
146
} ) {
147
147
beforeEachProperty ( ) ;
148
148
149
+ /** Endless stream of nonsense, similar to what you'd get if you tried to download a massive file */
150
+ const randomStream = RandomStream ( {
151
+ min : 250 , // in milliseconds
152
+ max : 1000 // in milliseconds
153
+ } ) ;
154
+
149
155
// Tell the FTP server to return success/failure for the various FTP
150
156
// paths with this dodgy method. Note that because the FTP server can
151
157
// only see paths and not host, we only send it the path of the req.
@@ -176,28 +182,19 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
176
182
} ) => {
177
183
const scope = nock ( url ) ;
178
184
179
- const intercept = scope . head (
180
- url . endsWith ( "/" ) ? "/" : ""
181
- ) ;
182
-
183
185
if ( success !== "error" ) {
184
- if ( ! disallowHead ) {
185
- intercept . reply (
186
- success === "success" ? 200 : 404
186
+ scope
187
+ . get ( url . endsWith ( "/" ) ? "/" : "" )
188
+ . reply (
189
+ success === "success" ? 200 : 404 ,
190
+ ( ) => {
191
+ return randomStream ;
192
+ }
187
193
) ;
188
- if ( success !== "success" ) {
189
- scope
190
- . get ( url . endsWith ( "/" ) ? "/" : "" )
191
- . reply ( 404 ) ;
192
- }
193
- } else {
194
- intercept . reply ( 405 ) ;
195
- scope
196
- . get ( url . endsWith ( "/" ) ? "/" : "" )
197
- . reply ( success === "success" ? 200 : 404 ) ;
198
- }
199
194
} else {
200
- intercept . replyWithError ( "fail" ) ;
195
+ scope
196
+ . get ( url . endsWith ( "/" ) ? "/" : "" )
197
+ . replyWithError ( "fail" ) ;
201
198
}
202
199
203
200
return scope ;
@@ -321,17 +318,19 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
321
318
. reply ( 201 ) ;
322
319
} ) ;
323
320
324
- return onRecordFound ( record , registry , 0 , 0 , 0 , fakeFtpHandler )
321
+ return onRecordFound ( record , registry , 0 , 0 , fakeFtpHandler )
325
322
. then ( ( ) => {
326
323
distScopes . forEach ( scope => scope . done ( ) ) ;
327
324
registryScope . done ( ) ;
328
325
} )
329
326
. then ( ( ) => {
330
327
afterEachProperty ( ) ;
328
+ randomStream . destroy ( ) ;
331
329
return true ;
332
330
} )
333
331
. catch ( e => {
334
332
afterEachProperty ( ) ;
333
+ randomStream . destroy ( ) ;
335
334
throw e ;
336
335
} ) ;
337
336
} ) ,
@@ -447,11 +446,6 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
447
446
448
447
allResults . forEach ( ( failureCodes , i ) => {
449
448
failureCodes . forEach ( failureCode => {
450
- scope
451
- . head (
452
- url . endsWith ( "/" ) ? "/" : ""
453
- )
454
- . reply ( failureCode ) ;
455
449
scope
456
450
. get (
457
451
url . endsWith ( "/" ) ? "/" : ""
@@ -463,7 +457,7 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
463
457
result === "fail429"
464
458
) {
465
459
scope
466
- . head (
460
+ . get (
467
461
url . endsWith ( "/" ) ? "/" : ""
468
462
)
469
463
. reply ( 429 ) ;
@@ -472,7 +466,7 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
472
466
473
467
if ( result === "success" ) {
474
468
scope
475
- . head ( url . endsWith ( "/" ) ? "/" : "" )
469
+ . get ( url . endsWith ( "/" ) ? "/" : "" )
476
470
. reply ( 200 ) ;
477
471
}
478
472
@@ -600,18 +594,14 @@ describe("onRecordFound", function(this: Mocha.ISuiteCallbackContext) {
600
594
const scope = scopeLookup [ base ] ;
601
595
602
596
failures . forEach ( failureCode => {
603
- scope
604
- . head ( uri . path ( ) )
605
- . delay ( delayMs )
606
- . reply ( failureCode ) ;
607
597
scope
608
598
. get ( uri . path ( ) )
609
599
. delay ( delayMs )
610
600
. reply ( failureCode ) ;
611
601
} ) ;
612
602
613
603
scope
614
- . head ( uri . path ( ) )
604
+ . get ( uri . path ( ) )
615
605
. delay ( delayMs )
616
606
. reply ( 200 ) ;
617
607
return scopeLookup ;
0 commit comments