@@ -267,7 +267,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
267
267
}
268
268
} ;
269
269
270
- const response = await helper . nodeRequest ( 'POST' , 'api/v1/builds' , data , config , API_URL ) ;
270
+ const response = await nodeRequest ( 'POST' , 'api/v1/builds' , data , config , API_URL ) ;
271
271
exports . debug ( 'Build creation successfull!' ) ;
272
272
process . env . BS_TESTOPS_BUILD_COMPLETED = true ;
273
273
setEnvironmentVariablesForRemoteReporter ( response . data . jwt , response . data . build_hashed_id , response . data . allow_screenshots , data . observability_version . sdkVersion ) ;
@@ -303,6 +303,56 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
303
303
}
304
304
}
305
305
306
+ const httpsScreenshotsKeepAliveAgent = new https . Agent ( {
307
+ keepAlive : true ,
308
+ timeout : 60000 ,
309
+ maxSockets : 2 ,
310
+ maxTotalSockets : 2
311
+ } ) ;
312
+
313
+ exports . httpsKeepAliveAgent = new https . Agent ( {
314
+ keepAlive : true ,
315
+ timeout : 60000 ,
316
+ maxSockets : 2 ,
317
+ maxTotalSockets : 2
318
+ } ) ;
319
+
320
+ const nodeRequest = ( type , url , data , config , api_url ) => {
321
+ return new Promise ( async ( resolve , reject ) => {
322
+ const options = { ...config , ...{
323
+ method : type ,
324
+ url : `${ api_url } /${ url } ` ,
325
+ body : data ,
326
+ json : config . headers [ 'Content-Type' ] === 'application/json' ,
327
+ agent : this . httpsKeepAliveAgent
328
+ } } ;
329
+
330
+ if ( url === exports . requestQueueHandler . screenshotEventUrl ) {
331
+ options . agent = httpsScreenshotsKeepAliveAgent ;
332
+ }
333
+
334
+ request ( options , function callback ( error , response , body ) {
335
+ if ( error ) {
336
+ reject ( error ) ;
337
+ } else if ( response . statusCode != 200 ) {
338
+ reject ( response && response . body ? response . body : `Received response from BrowserStack Server with status : ${ response . statusCode } ` ) ;
339
+ } else {
340
+ try {
341
+ if ( typeof ( body ) !== 'object' ) body = JSON . parse ( body ) ;
342
+ } catch ( e ) {
343
+ if ( ! url . includes ( '/stop' ) ) {
344
+ reject ( 'Not a JSON response from BrowserStack Server' ) ;
345
+ }
346
+ }
347
+ resolve ( {
348
+ data : body
349
+ } ) ;
350
+ }
351
+ } ) ;
352
+ } ) ;
353
+ }
354
+
355
+
306
356
exports . getHookDetails = ( hookTitle ) => {
307
357
if ( ! hookTitle || typeof ( hookTitle ) != 'string' ) return [ null , null ] ;
308
358
if ( hookTitle . indexOf ( 'hook:' ) !== - 1 ) {
@@ -355,7 +405,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
355
405
} ;
356
406
357
407
try {
358
- const response = await helper . nodeRequest ( 'POST' , eventUrl , data , config , API_URL ) ;
408
+ const response = await nodeRequest ( 'POST' , eventUrl , data , config , API_URL ) ;
359
409
if ( response . data . error ) {
360
410
throw ( { message : response . data . error } ) ;
361
411
} else {
@@ -418,7 +468,7 @@ exports.uploadEventData = async (eventData, run=0) => {
418
468
} ;
419
469
420
470
try {
421
- const response = await helper . nodeRequest ( 'POST' , event_api_url , data , config , API_URL ) ;
471
+ const response = await nodeRequest ( 'POST' , event_api_url , data , config , API_URL ) ;
422
472
if ( response . data . error ) {
423
473
throw ( { message : response . data . error } ) ;
424
474
} else {
@@ -527,7 +577,7 @@ exports.stopBuildUpstream = async () => {
527
577
} ;
528
578
529
579
try {
530
- const response = await helper . nodeRequest ( 'PUT' , `api/v1/builds/${ process . env . BS_TESTOPS_BUILD_HASHED_ID } /stop` , data , config , API_URL ) ;
580
+ const response = await nodeRequest ( 'PUT' , `api/v1/builds/${ process . env . BS_TESTOPS_BUILD_HASHED_ID } /stop` , data , config , API_URL ) ;
531
581
if ( response . data && response . data . error ) {
532
582
throw ( { message : response . data . error } ) ;
533
583
} else {
0 commit comments