@@ -1052,6 +1052,11 @@ async fn hot_author(shared: Arc<Shared>, index: usize) {
10521052 _ = tokio:: time:: sleep_until( due. into( ) ) => { }
10531053 _ = stopping( & shared) => return ,
10541054 }
1055+ // An overdue arrival and the stop can be ready together, and `select!`
1056+ // picks either; start nothing new once the run is stopping.
1057+ if stopped ( & shared) {
1058+ return ;
1059+ }
10551060 if next_reply == Some ( due) {
10561061 next_reply = rng. after ( profile. replies_per_hour ) ;
10571062 let event = EventBuilder :: new (
@@ -1765,10 +1770,11 @@ hold_secs = 2
17651770 channel : String ,
17661771 }
17671772
1768- /// Runs two hot-thread authors for a second against a relay whose root
1769- /// lookup returns a newer reply-shaped decoy by the root's author, plus
1770- /// the hot root itself when `seeded`.
1771- async fn hot_thread_run ( seeded : bool ) -> HotRun {
1773+ /// Runs `[hot_thread]` section `hot` for a second against a relay whose
1774+ /// root lookup returns a newer reply-shaped decoy by the root's author,
1775+ /// plus the hot root itself when `seeded`, and which takes `delay` to
1776+ /// accept each event.
1777+ async fn hot_thread_run ( seeded : bool , hot : & str , delay : Duration ) -> HotRun {
17721778 let author = hot_root_keys ( "t" ) ;
17731779 let channel = identity:: channel_id ( "t" , 0 , 0 ) ;
17741780 let root = EventBuilder :: new ( kind ( KIND_STREAM_MESSAGE ) , HOT_ROOT_PREFIX )
@@ -1792,6 +1798,9 @@ hold_secs = 2
17921798 if target == "/events" {
17931799 let event: Event = serde_json:: from_slice ( body) . unwrap ( ) ;
17941800 post_log. lock ( ) . unwrap ( ) . push ( event) ;
1801+ if !delay. is_zero ( ) {
1802+ tokio:: task:: block_in_place ( || std:: thread:: sleep ( delay) ) ;
1803+ }
17951804 return ( 200 , json ! ( { "accepted" : true , "message" : "" } ) . to_string ( ) ) ;
17961805 }
17971806 let filter: Value = serde_json:: from_slice ( body) . unwrap ( ) ;
@@ -1819,9 +1828,7 @@ humans = 0
18191828agents = 0
18201829channels_per_member = 1
18211830[hot_thread]
1822- authors = 2
1823- replies_per_hour = 36000.0
1824- fetches_per_hour = 36000.0
1831+ {hot}
18251832[[ramp]]
18261833users = 1.0
18271834hold_secs = 1
@@ -1842,9 +1849,11 @@ hold_secs = 1
18421849 }
18431850 }
18441851
1852+ const TWO_AUTHORS : & str = "authors = 2\n replies_per_hour = 36000.0\n fetches_per_hour = 36000.0" ;
1853+
18451854 #[ tokio:: test]
18461855 async fn hot_thread_authors_reply_to_the_hot_root_and_fail_without_it ( ) {
1847- let run = hot_thread_run ( true ) . await ;
1856+ let run = hot_thread_run ( true , TWO_AUTHORS , Duration :: ZERO ) . await ;
18481857 let report = run. outcome . expect ( "hot-thread run passes" ) ;
18491858 assert_eq ! ( report[ "steps" ] [ 0 ] [ "hot_authors" ] , 2 , "{report}" ) ;
18501859 assert ! ( !run. posted. is_empty( ) , "{report}" ) ;
@@ -1881,12 +1890,24 @@ hold_secs = 1
18811890 assert ! ( ops[ "hot_reply" ] [ "count" ] . as_u64( ) > Some ( 0 ) , "{report}" ) ;
18821891
18831892 // Without a seeded hot root the authors post nothing and the step aborts.
1884- let run = hot_thread_run ( false ) . await ;
1893+ let run = hot_thread_run ( false , TWO_AUTHORS , Duration :: ZERO ) . await ;
18851894 let report = run. outcome . expect_err ( "a missing hot root fails the run" ) ;
18861895 assert ! ( run. posted. is_empty( ) ) ;
18871896 let reason = report[ "steps" ] [ 0 ] [ "abort_reason" ]
18881897 . as_str ( )
18891898 . unwrap_or_default ( ) ;
18901899 assert ! ( reason. starts_with( "thread_fetch" ) , "{report}" ) ;
18911900 }
1901+
1902+ /// Every author is mid-reply at the stop, with its next reply already
1903+ /// due when that one settles. Each may finish the reply it started, but
1904+ /// must start no other: one reply per author settles during shutdown.
1905+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
1906+ async fn hot_thread_authors_start_nothing_once_the_run_stops ( ) {
1907+ let busy = "authors = 8\n replies_per_hour = 36000000.0" ;
1908+ let run = hot_thread_run ( true , busy, Duration :: from_millis ( 300 ) ) . await ;
1909+ let report = run. outcome . expect ( "in-flight replies settle in the grace" ) ;
1910+ let settled = & report[ "shutdown" ] [ "ops" ] [ "hot_reply" ] [ "count" ] ;
1911+ assert_eq ! ( settled. as_u64( ) , Some ( 8 ) , "{report}" ) ;
1912+ }
18921913}
0 commit comments