@@ -798,7 +798,7 @@ const buildAppUnderTest = (options?: {
798798 } ) ,
799799 Layer . mock ( ThreadDeletionReactor ) ( {
800800 start : ( ) => Effect . void ,
801- drain : Effect . void ,
801+ drainThrough : ( ) => Effect . void ,
802802 ...options ?. layers ?. threadDeletionReactor ,
803803 } ) ,
804804 ) ,
@@ -8449,22 +8449,24 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
84498449 } ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
84508450 ) ;
84518451
8452- it . effect ( "waits for deletion cleanup before re-creating a thread id " , ( ) =>
8452+ it . effect ( "drains deletion cleanup through the re-created thread event " , ( ) =>
84538453 Effect . gen ( function * ( ) {
84548454 // A draft retry reuses the thread id its failed bootstrap deleted. The
84558455 // deletion reactor stops sessions and closes terminals by that id, so
8456- // both thread.create paths must let its queue drain first.
8456+ // both thread.create paths use the created event as a fence, then drain
8457+ // cleanup before handing the new incarnation to resource-owning work.
84578458 const trace : Array < string > = [ ] ;
84588459 const drainRequested = yield * Deferred . make < void > ( ) ;
84598460 const cleanupDone = yield * Deferred . make < void > ( ) ;
84608461 yield * buildAppUnderTest ( {
84618462 layers : {
84628463 threadDeletionReactor : {
8463- drain : Effect . gen ( function * ( ) {
8464- trace . push ( "drain" ) ;
8465- yield * Deferred . succeed ( drainRequested , undefined ) ;
8466- yield * Deferred . await ( cleanupDone ) ;
8467- } ) ,
8464+ drainThrough : ( sequence ) =>
8465+ Effect . gen ( function * ( ) {
8466+ trace . push ( `drain:${ sequence } ` ) ;
8467+ yield * Deferred . succeed ( drainRequested , undefined ) ;
8468+ yield * Deferred . await ( cleanupDone ) ;
8469+ } ) ,
84688470 } ,
84698471 orchestrationEngine : {
84708472 dispatch : ( command ) =>
@@ -8500,15 +8502,16 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
85008502 } ) ,
85018503 ) ;
85028504 yield * Deferred . await ( drainRequested ) ;
8503- assert . deepEqual ( trace , [ "drain" ] ) ;
8505+ assert . deepEqual ( trace , [ "thread.create" , " drain:1 "] ) ;
85048506 yield * Deferred . succeed ( cleanupDone , undefined ) ;
85058507 yield * Fiber . join ( directCreate ) ;
85068508 } ) ,
85078509 ) ,
85088510 ) ;
8509- assert . deepEqual ( trace , [ "drain " , "thread.create " ] ) ;
8511+ assert . deepEqual ( trace , [ "thread.create " , "drain:1 " ] ) ;
85108512
8511- // Cleanup is already released; the bootstrap path must still drain first.
8513+ // Cleanup is already released; the bootstrap path must still drain
8514+ // between creating the thread and starting its turn.
85128515 trace . length = 0 ;
85138516 yield * Effect . scoped (
85148517 withWsRpcClient ( wsUrl , ( client ) =>
@@ -8547,7 +8550,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
85478550 } ) ,
85488551 ) ,
85498552 ) ;
8550- assert . deepEqual ( trace , [ "drain " , "thread.create " , "thread.turn.start" ] ) ;
8553+ assert . deepEqual ( trace , [ "thread.create " , "drain:1 " , "thread.turn.start" ] ) ;
85518554 } ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
85528555 ) ;
85538556
0 commit comments