@@ -175,29 +175,49 @@ test("reports a failed registered service without spawning", async () => {
175175 expect ( process . exitCode ) . toBe ( null )
176176} )
177177
178- test ( "evicts an unresponsive registered service before starting its replacement" , async ( ) => {
178+ test ( "a registered service it did not start that answers probes slowly survives ensure" , async ( ) => {
179+ await using fixture = await serviceFixture ( )
180+ const registration = fixture . registration
181+ const existing = fixture . spawn ( "slow" , "5" )
182+ await fixture . waitForFile ( )
183+ const original = await Bun . file ( registration ) . json ( )
184+
185+ const endpoint = await run ( ensure ( { file : registration , version : "test" , command : fixture . command ( "record-start" ) } ) )
186+
187+ expect ( ( await Bun . file ( registration + ".requests" ) . text ( ) ) . trim ( ) . split ( "\n" ) ) . toHaveLength ( 5 )
188+ expect ( endpoint . url ) . toBe ( original . url )
189+ expect ( existing . exitCode ) . toBe ( null )
190+ expect ( await fixture . signal ( ) ) . toBeUndefined ( )
191+ expect ( await Bun . file ( registration + ".started" ) . exists ( ) ) . toBe ( false )
192+ expect ( await status ( endpoint . url ) ) . toMatchObject ( { version : "test" , pid : original . pid } )
193+ } )
194+
195+ test ( "a hanging registered service it did not start is waited for, then reported and left running" , async ( ) => {
179196 await using fixture = await serviceFixture ( )
180197 const registration = fixture . registration
181198 const existing = fixture . spawn ( "hanging" )
182199 await fixture . waitForFile ( )
183200 const original = await Bun . file ( registration ) . json ( )
201+ const waits : string [ ] = [ ]
184202
185- const endpoint = await run (
203+ const error = await run (
186204 ensure ( {
187205 file : registration ,
188206 version : "test" ,
189- command : fixture . command ( "delayed" , "10" ) ,
207+ command : fixture . command ( "record-start" ) ,
208+ onWait : ( url ) => waits . push ( url ) ,
190209 } ) ,
191- )
192- const replacement = await Bun . file ( registration ) . json ( )
193- fixture . track ( replacement . pid )
210+ ) . catch ( ( error : unknown ) => error )
194211
195- expect ( ( await Bun . file ( registration + ".requests" ) . text ( ) ) . trim ( ) . split ( "\n" ) ) . toHaveLength ( 3 )
196- expect ( await existing . exited ) . toBe ( stoppedExitCode )
197- expect ( replacement . pid ) . not . toBe ( original . pid )
198- expect ( endpoint . url ) . toBe ( replacement . url )
199- expect ( await status ( endpoint . url ) ) . toMatchObject ( { version : "test" , pid : replacement . pid } )
200- } )
212+ expect ( error ) . toBeInstanceOf ( Error )
213+ expect ( String ( error ) ) . toContain ( `Background service at ${ original . url } (pid ${ original . pid } ) did not answer` )
214+ expect ( String ( error ) ) . toContain ( "left running" )
215+ expect ( waits ) . toEqual ( [ original . url ] )
216+ expect ( existing . exitCode ) . toBe ( null )
217+ expect ( await fixture . signal ( ) ) . toBeUndefined ( )
218+ expect ( await Bun . file ( registration ) . json ( ) ) . toEqual ( original )
219+ expect ( await Bun . file ( registration + ".started" ) . exists ( ) ) . toBe ( false )
220+ } , 10_000 )
201221
202222test ( "signals an unresponsive registered service process" , async ( ) => {
203223 await using fixture = await serviceFixture ( )
0 commit comments