@@ -11,6 +11,7 @@ import {
11
11
} from '../workers/serve-testing/worker-types.js' ;
12
12
import { EvalID , Gateway } from './gateway.js' ;
13
13
import { BrowserAgentTaskInput } from '../testing/browser-agent/models.js' ;
14
+ import PQueue from 'p-queue' ;
14
15
15
16
/** Attempts to run & test an eval app. */
16
17
export async function serveAndTestApp (
@@ -19,6 +20,8 @@ export async function serveAndTestApp(
19
20
appDirectoryPath : string ,
20
21
env : Environment ,
21
22
rootPromptDef : RootPromptDefinition ,
23
+ workerConcurrencyQueue : PQueue ,
24
+ abortSignal : AbortSignal ,
22
25
progress : ProgressLogger ,
23
26
skipScreenshots : boolean ,
24
27
skipAxeTesting : boolean ,
@@ -43,37 +46,41 @@ export async function serveAndTestApp(
43
46
userJourneyAgentTaskInput,
44
47
} ;
45
48
46
- return await new Promise < ServeTestingResult > ( ( resolve , reject ) => {
47
- const child : ChildProcess = fork (
48
- path . resolve (
49
- import . meta. dirname ,
50
- '../workers/serve-testing/worker.js'
51
- )
52
- ) ;
53
- child . send ( serveParams ) ;
49
+ return await workerConcurrencyQueue . add (
50
+ ( ) =>
51
+ new Promise < ServeTestingResult > ( ( resolve , reject ) => {
52
+ const child : ChildProcess = fork (
53
+ path . resolve (
54
+ import . meta. dirname ,
55
+ '../workers/serve-testing/worker.js'
56
+ ) ,
57
+ { signal : abortSignal }
58
+ ) ;
59
+ child . send ( serveParams ) ;
54
60
55
- child . on (
56
- 'message' ,
57
- async ( result : ServeTestingWorkerResponseMessage ) => {
58
- if ( result . type === 'result' ) {
61
+ child . on (
62
+ 'message' ,
63
+ async ( result : ServeTestingWorkerResponseMessage ) => {
64
+ if ( result . type === 'result' ) {
65
+ await killChildProcessGracefully ( child ) ;
66
+ resolve ( result . payload ) ;
67
+ } else {
68
+ progress . log (
69
+ rootPromptDef ,
70
+ result . payload . state ,
71
+ result . payload . message ,
72
+ result . payload . details
73
+ ) ;
74
+ }
75
+ }
76
+ ) ;
77
+ child . on ( 'error' , async ( err ) => {
59
78
await killChildProcessGracefully ( child ) ;
60
- resolve ( result . payload ) ;
61
- } else {
62
- progress . log (
63
- rootPromptDef ,
64
- result . payload . state ,
65
- result . payload . message ,
66
- result . payload . details
67
- ) ;
68
- }
69
- }
70
- ) ;
71
- child . on ( 'error' , async ( err ) => {
72
- console . error ( 'Caught error' ) ;
73
- await killChildProcessGracefully ( child ) ;
74
- reject ( err ) ;
75
- } ) ;
76
- } ) ;
79
+ reject ( err ) ;
80
+ } ) ;
81
+ } ) ,
82
+ { throwOnTimeout : true }
83
+ ) ;
77
84
}
78
85
) ;
79
86
0 commit comments