@@ -2025,6 +2025,7 @@ mod batching_tests {
20252025 hive : & Hive < DefaultQueen < ThunkWorker < ThreadId > > , T > ,
20262026 num_threads : usize ,
20272027 batch_limit : usize ,
2028+ assert_exact : bool ,
20282029 ) {
20292030 let tasks_per_thread = batch_limit + 2 ;
20302031 let ( tx, rx) = crate :: hive:: outcome_channel ( ) ;
@@ -2038,52 +2039,83 @@ mod batching_tests {
20382039 hive. join ( ) ;
20392040 let thread_counts = count_thread_ids ( rx, task_ids) ;
20402041 assert_eq ! ( thread_counts. len( ) , num_threads) ;
2041- assert ! (
2042- thread_counts
2043- . values( )
2044- . all( |& count| count == tasks_per_thread)
2042+ assert_eq ! (
2043+ thread_counts. values( ) . sum:: <usize >( ) ,
2044+ tasks_per_thread * num_threads
20452045 ) ;
2046+ if assert_exact {
2047+ assert ! (
2048+ thread_counts
2049+ . values( )
2050+ . all( |& count| count == tasks_per_thread)
2051+ ) ;
2052+ } else {
2053+ assert ! ( thread_counts. values( ) . all( |& count| count > 0 ) ) ;
2054+ }
20462055 }
20472056
20482057 #[ rstest]
2049- fn test_batching < B , F > ( #[ values( channel_builder, workstealing_builder) ] builder_factory : F )
2050- where
2051- B : TaskQueuesBuilder ,
2052- F : Fn ( bool ) -> B ,
2053- {
2058+ fn test_batching_channel ( ) {
20542059 const NUM_THREADS : usize = 4 ;
20552060 const BATCH_LIMIT : usize = 24 ;
2056- let hive = builder_factory ( false )
2061+ let hive = channel_builder ( false )
20572062 . with_worker_default ( )
20582063 . num_threads ( NUM_THREADS )
20592064 . batch_limit ( BATCH_LIMIT )
20602065 . build ( ) ;
2061- run_test ( & hive, NUM_THREADS , BATCH_LIMIT ) ;
2066+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT , true ) ;
20622067 }
20632068
20642069 #[ rstest]
2065- fn test_set_batch_limit < B , F > (
2066- #[ values( channel_builder, workstealing_builder) ] builder_factory : F ,
2067- ) where
2068- B : TaskQueuesBuilder ,
2069- F : Fn ( bool ) -> B ,
2070- {
2070+ fn test_batching_workstealing ( ) {
2071+ const NUM_THREADS : usize = 4 ;
2072+ const BATCH_LIMIT : usize = 24 ;
2073+ let hive = workstealing_builder ( false )
2074+ . with_worker_default ( )
2075+ . num_threads ( NUM_THREADS )
2076+ . batch_limit ( BATCH_LIMIT )
2077+ . build ( ) ;
2078+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT , false ) ;
2079+ }
2080+
2081+ #[ rstest]
2082+ fn test_set_batch_limit_channel ( ) {
20712083 const NUM_THREADS : usize = 4 ;
20722084 const BATCH_LIMIT_0 : usize = 10 ;
2073- const BATCH_LIMIT_1 : usize = 20 ;
2074- const BATCH_LIMIT_2 : usize = 50 ;
2075- let hive = builder_factory ( false )
2085+ const BATCH_LIMIT_1 : usize = 50 ;
2086+ const BATCH_LIMIT_2 : usize = 20 ;
2087+ let hive = channel_builder ( false )
20762088 . with_worker_default ( )
20772089 . num_threads ( NUM_THREADS )
20782090 . batch_limit ( BATCH_LIMIT_0 )
20792091 . build ( ) ;
2080- run_test ( & hive, NUM_THREADS , BATCH_LIMIT_0 ) ;
2092+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_0 , true ) ;
20812093 // increase batch size
2082- hive. set_worker_batch_limit ( BATCH_LIMIT_2 ) ;
2083- run_test ( & hive, NUM_THREADS , BATCH_LIMIT_2 ) ;
2094+ hive. set_worker_batch_limit ( BATCH_LIMIT_1 ) ;
2095+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_1 , true ) ;
20842096 // decrease batch size
2097+ hive. set_worker_batch_limit ( BATCH_LIMIT_2 ) ;
2098+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_2 , true ) ;
2099+ }
2100+
2101+ #[ rstest]
2102+ fn test_set_batch_limit_workstealing ( ) {
2103+ const NUM_THREADS : usize = 4 ;
2104+ const BATCH_LIMIT_0 : usize = 10 ;
2105+ const BATCH_LIMIT_1 : usize = 50 ;
2106+ const BATCH_LIMIT_2 : usize = 20 ;
2107+ let hive = workstealing_builder ( false )
2108+ . with_worker_default ( )
2109+ . num_threads ( NUM_THREADS )
2110+ . batch_limit ( BATCH_LIMIT_0 )
2111+ . build ( ) ;
2112+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_0 , false ) ;
2113+ // increase batch size
20852114 hive. set_worker_batch_limit ( BATCH_LIMIT_1 ) ;
2086- run_test ( & hive, NUM_THREADS , BATCH_LIMIT_1 ) ;
2115+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_1 , false ) ;
2116+ // decrease batch size
2117+ hive. set_worker_batch_limit ( BATCH_LIMIT_2 ) ;
2118+ run_test ( & hive, NUM_THREADS , BATCH_LIMIT_2 , false ) ;
20872119 }
20882120
20892121 #[ rstest]
0 commit comments