@@ -73,7 +73,12 @@ class FakeService {
7373 this . calls . push ( "resume" ) ;
7474 this . state = "RUNNING" ;
7575 if ( this . sendResumeHook && this . listener ) {
76- await send ( this . listener , `${ HOOK_PATH_PREFIX } resume` , { } ) ;
76+ await send (
77+ this . listener ,
78+ `${ HOOK_PATH_PREFIX } resume` ,
79+ { } ,
80+ LAMBDA_HOOK_HEADERS ,
81+ ) ;
7782 }
7883 return { } ;
7984 }
@@ -94,18 +99,29 @@ class FakeService {
9499 }
95100}
96101
97- /** Sends one request straight to the listener, and resolves with the status. */
102+ /**
103+ * The headers of Lambda's own hook calls, as measured in us-east-1. The
104+ * worker acts on the `resume` hook only for a local Host without a request ID.
105+ */
106+ const LAMBDA_HOOK_HEADERS = { host : "localhost:8080" } ;
107+
108+ /**
109+ * Sends one request straight to the listener, and resolves with the status.
110+ * A job request comes through the endpoint, so it carries no Lambda hook
111+ * headers by default.
112+ */
98113function send (
99114 listener : MicrovmWorkerListener ,
100115 path : string ,
101116 body : unknown ,
117+ headers : Record < string , string > = { } ,
102118) : Promise < number > {
103119 return new Promise ( ( resolve ) => {
104120 const request = Object . assign (
105121 Readable . from ( [
106122 Buffer . from ( typeof body === "string" ? body : JSON . stringify ( body ) ) ,
107123 ] ) ,
108- { url : path , method : "POST" , headers : { } } ,
124+ { url : path , method : "POST" , headers } ,
109125 ) ;
110126 let status = 0 ;
111127 const response = {
@@ -236,14 +252,19 @@ describe("the request step against the real worker listener", () => {
236252 ) ;
237253
238254 const runHook = ( ) =>
239- send ( listener , `${ HOOK_PATH_PREFIX } run` , {
240- microvmId : "mvm-1" ,
241- runHookPayload : JSON . stringify ( {
242- version : 1 ,
243- region : REGION ,
244- autoSuspendIdleSeconds : IDLE_SECONDS ,
245- } ) ,
246- } ) ;
255+ send (
256+ listener ,
257+ `${ HOOK_PATH_PREFIX } run` ,
258+ {
259+ microvmId : "mvm-1" ,
260+ runHookPayload : JSON . stringify ( {
261+ version : 1 ,
262+ region : REGION ,
263+ autoSuspendIdleSeconds : IDLE_SECONDS ,
264+ } ) ,
265+ } ,
266+ LAMBDA_HOOK_HEADERS ,
267+ ) ;
247268
248269 /** Advances fake time in steps until `promise` settles. */
249270 async function settle < T > ( promise : Promise < T > , maxMs : number ) : Promise < T > {
@@ -275,10 +296,15 @@ describe("the request step against the real worker listener", () => {
275296 // The service suspends the MicroVM. The next state check after a 503
276297 // finds it SUSPENDED and resumes it. The resume hook ends the refusal.
277298 service . finishSuspend ( ) ;
299+ const suspendedAt = Date . now ( ) ;
278300
279301 await settle ( delivery , 60_000 ) ;
280302 await listener . idle ( ) ;
281303
304+ // Without the resume hook, the refusal would last 30 seconds after the
305+ // suspend call returned. The next test covers that fallback.
306+ expect ( Date . now ( ) - suspendedAt ) . toBeLessThan ( 30_000 ) ;
307+
282308 expect ( statuses . at ( - 1 ) ) . toBe ( 202 ) ;
283309 expect ( service . calls ) . toContain ( "get:SUSPENDED" ) ;
284310 expect ( service . calls . filter ( ( c ) => c === "resume" ) ) . toHaveLength ( 1 ) ;
0 commit comments