@@ -3005,6 +3005,68 @@ public async Task DurableEntity_StringStoreWithCreateDelete(bool extendedSession
3005
3005
}
3006
3006
}
3007
3007
3008
+ /// <summary>
3009
+ /// End-to-end test which validates batching of entity signals.
3010
+ /// </summary>
3011
+ [ Theory ]
3012
+ [ Trait ( "Category" , PlatformSpecificHelpers . TestCategory ) ]
3013
+ [ InlineData ( true ) ]
3014
+ [ InlineData ( false ) ]
3015
+ public async Task DurableEntity_BatchedSignals ( bool extendedSessions )
3016
+ {
3017
+ using ( var host = TestHelpers . GetJobHost (
3018
+ this . loggerProvider ,
3019
+ nameof ( this . DurableEntity_BatchedSignals ) ,
3020
+ extendedSessions ) )
3021
+ {
3022
+ await host . StartAsync ( ) ;
3023
+
3024
+ int numIterations = 100 ;
3025
+ var entityId = new EntityId ( nameof ( TestEntities . BatchEntity ) , Guid . NewGuid ( ) . ToString ( ) ) ;
3026
+ var client = await host . GetEntityClientAsync ( entityId , this . output ) ;
3027
+
3028
+ // send a number of signals immediately after each other
3029
+ List < Task > tasks = new List < Task > ( ) ;
3030
+ for ( int i = 0 ; i < numIterations ; i ++ )
3031
+ {
3032
+ tasks . Add ( client . SignalEntity ( this . output , i . ToString ( ) ) ) ;
3033
+ }
3034
+
3035
+ await Task . WhenAll ( tasks ) ;
3036
+
3037
+ var result = await client . WaitForEntityState < List < ( int , int ) > > (
3038
+ this . output ,
3039
+ timeout : Debugger . IsAttached ? TimeSpan . FromMinutes ( 5 ) : TimeSpan . FromSeconds ( 20 ) ,
3040
+ list => list . Count == numIterations ? null : $ "waiting for { numIterations - list . Count } signals") ;
3041
+
3042
+ // validate the batching positions and sizes
3043
+ int ? cursize = null ;
3044
+ int curpos = 0 ;
3045
+ int numBatches = 0 ;
3046
+ foreach ( var ( position , size ) in result )
3047
+ {
3048
+ if ( cursize == null )
3049
+ {
3050
+ cursize = size ;
3051
+ curpos = 0 ;
3052
+ numBatches ++ ;
3053
+ }
3054
+
3055
+ Assert . Equal ( curpos , position ) ;
3056
+
3057
+ if ( ++ curpos == cursize )
3058
+ {
3059
+ cursize = null ;
3060
+ }
3061
+ }
3062
+
3063
+ // there should always be some batching going on
3064
+ Assert . True ( numBatches < numIterations ) ;
3065
+
3066
+ await host . StopAsync ( ) ;
3067
+ }
3068
+ }
3069
+
3008
3070
/// <summary>
3009
3071
/// End-to-end test which validates exception handling in entity operations.
3010
3072
/// </summary>
0 commit comments