@@ -392,4 +392,76 @@ describe("SplitPDF succeeds for large PDF with high concurrency", () => {
392392 expect ( res . elements ?. length ) . toBeGreaterThan ( 0 ) ;
393393 } ,
394394 300000 ) ;
395- } ) ;
395+ } ) ;
396+
397+
398+ describe ( "SplitPDF async can be used to send multiple files concurrently" , ( ) => {
399+ const FAKE_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
400+
401+ it . each ( [
402+ `${ localServer } /general/v0/general` ,
403+ ] ) ( "succeed" , async ( serverURL ) => {
404+ const client = new UnstructuredClient ( {
405+ serverURL : serverURL ,
406+ security : {
407+ apiKeyAuth : FAKE_API_KEY ,
408+ } ,
409+ } ) ;
410+
411+ const file = {
412+ content : readFileSync ( "test/data/layout-parser-paper.pdf" ) ,
413+ fileName : "test/data/layout-parser-paper.pdf"
414+ } ;
415+
416+ const RequestsParams = [
417+ {
418+ files : file ,
419+ splitPdfPage : true ,
420+ strategy : Strategy . Fast ,
421+ splitPdfPageRange : [ 1 , 3 ] ,
422+ languages : [ "eng" ] ,
423+ } ,
424+ {
425+ files : file ,
426+ splitPdfPage : true ,
427+ strategy : Strategy . Fast ,
428+ splitPdfPageRange : [ 10 , 12 ] ,
429+ languages : [ "eng" ] ,
430+ }
431+ ] ;
432+
433+ // Process requests serially
434+ const serialElements : any [ ] [ ] = [ ] ;
435+ for ( const requestParams of RequestsParams ) {
436+ const res : PartitionResponse = await client . general . partition ( {
437+ partitionParameters : {
438+ ...requestParams
439+ } ,
440+ } ) ;
441+ expect ( res . statusCode ) . toEqual ( 200 ) ;
442+ if ( res . elements ) {
443+ serialElements . push ( res . elements ) ;
444+ }
445+ }
446+
447+ // Process requests concurrently
448+ const concurrentElements : any [ ] [ ] = [ ] ;
449+ const concurrentResponses = await Promise . all ( RequestsParams . map ( req =>
450+ client . general . partition ( {
451+ partitionParameters : req
452+ } )
453+ ) ) ;
454+
455+ for ( const res of concurrentResponses ) {
456+ expect ( res . statusCode ) . toEqual ( 200 ) ;
457+ if ( res . elements ) {
458+ concurrentElements . push ( res . elements ) ;
459+ }
460+ }
461+
462+ const isEqual = JSON . stringify ( serialElements ) === JSON . stringify ( concurrentElements ) ;
463+ expect ( isEqual ) . toBe ( true ) ;
464+
465+ } ,
466+ 300000 ) ;
467+ } ) ;
0 commit comments