File tree Expand file tree Collapse file tree 4 files changed +35
-6
lines changed 
src/libraries/System.Threading.RateLimiting 
src/System/Threading/RateLimiting Expand file tree Collapse file tree 4 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ internal sealed class ChainedPartitionedRateLimiter<TResource> : PartitionedRate
2020
2121        public  ChainedPartitionedRateLimiter ( PartitionedRateLimiter < TResource > [ ]  limiters ) 
2222        { 
23-             _limiters  =  limiters ; 
23+             _limiters  =  ( PartitionedRateLimiter < TResource > [ ] ) limiters . Clone ( ) ; 
2424        } 
2525
2626        public  override  RateLimiterStatistics ?  GetStatistics ( TResource  resource ) 
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ internal sealed partial class ChainedRateLimiter : RateLimiter
2020
2121        public  ChainedRateLimiter ( RateLimiter [ ]  limiters ) 
2222        { 
23-             _limiters  =  limiters ; 
23+             _limiters  =  ( RateLimiter [ ] ) limiters . Clone ( ) ; 
2424        } 
2525
2626        public  override  RateLimiterStatistics ?  GetStatistics ( ) 
Original file line number Diff line number Diff line change 11// Licensed to the .NET Foundation under one or more agreements. 
22// The .NET Foundation licenses this file to you under the MIT license. 
33
4- using  System ; 
54using  System . Collections . Generic ; 
65using  System . Linq ; 
7- using  System . Text ; 
86using  System . Threading . Tasks ; 
97using  Xunit ; 
108
@@ -55,6 +53,20 @@ public async Task DisposeAsyncMakesMethodsThrow()
5553            await  Assert . ThrowsAsync < ObjectDisposedException > ( async  ( )  =>  await  chainedLimiter . AcquireAsync ( ) ) ; 
5654        } 
5755
56+         [ Fact ] 
57+         public  void  ArrayChangesAreIgnored ( ) 
58+         { 
59+             using  var  limiter1  =  new  CustomizableLimiter  {  IdleDurationImpl  =  ( )  =>  TimeSpan . FromMilliseconds ( 1 )  } ; 
60+             using  var  limiter2  =  new  CustomizableLimiter  {  IdleDurationImpl  =  ( )  =>  TimeSpan . FromMilliseconds ( 2 )  } ; 
61+             var  limiters  =  new  RateLimiter [ ]  {  limiter1  } ; 
62+             var  chainedLimiter  =  RateLimiter . CreateChained ( limiters ) ; 
63+ 
64+             limiters [ 0 ]  =  limiter2 ; 
65+ 
66+             var  idleDuration  =  chainedLimiter . IdleDuration ; 
67+             Assert . Equal ( 1 ,  idleDuration . Value . TotalMilliseconds ) ; 
68+         } 
69+ 
5870        [ Fact ] 
5971        public  void  GetStatisticsReturnsLowestOrAggregateValues ( ) 
6072        { 
Original file line number Diff line number Diff line change 11// Licensed to the .NET Foundation under one or more agreements. 
22// The .NET Foundation licenses this file to you under the MIT license. 
33
4- using  System ; 
54using  System . Collections . Generic ; 
65using  System . Linq ; 
7- using  System . Text ; 
86using  System . Threading . Tasks ; 
97using  Xunit ; 
108
@@ -89,6 +87,25 @@ public async Task DisposeAsyncMakesMethodsThrow()
8987            await  Assert . ThrowsAsync < ObjectDisposedException > ( async  ( )  =>  await  chainedLimiter . AcquireAsync ( "" ) ) ; 
9088        } 
9189
90+         [ Fact ] 
91+         public  void  ArrayChangesAreIgnored ( ) 
92+         { 
93+             using  var  limiter1  =  PartitionedRateLimiter . Create < string ,  int > ( resource => 
94+             { 
95+                 return  RateLimitPartition . Get ( 1 ,  key =>  new  NotImplementedLimiter ( ) ) ; 
96+             } ) ; 
97+             using  var  limiter2  =  PartitionedRateLimiter . Create < string ,  int > ( resource => 
98+             { 
99+                 return  RateLimitPartition . Get ( 1 ,  key =>  new  CustomizableLimiter ( ) ) ; 
100+             } ) ; 
101+             var  limiters  =  new  PartitionedRateLimiter < string > [ ]  {  limiter1  } ; 
102+             var  chainedLimiter  =  PartitionedRateLimiter . CreateChained ( limiters ) ; 
103+ 
104+             limiters [ 0 ]  =  limiter2 ; 
105+ 
106+             Assert . Throws < NotImplementedException > ( ( )  =>  chainedLimiter . AttemptAcquire ( "" ) ) ; 
107+         } 
108+ 
92109        [ Fact ] 
93110        public  void  GetStatisticsReturnsLowestOrAggregateValues ( ) 
94111        { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments