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
20
20
21
21
public ChainedPartitionedRateLimiter ( PartitionedRateLimiter < TResource > [ ] limiters )
22
22
{
23
- _limiters = limiters ;
23
+ _limiters = ( PartitionedRateLimiter < TResource > [ ] ) limiters . Clone ( ) ;
24
24
}
25
25
26
26
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
20
20
21
21
public ChainedRateLimiter ( RateLimiter [ ] limiters )
22
22
{
23
- _limiters = limiters ;
23
+ _limiters = ( RateLimiter [ ] ) limiters . Clone ( ) ;
24
24
}
25
25
26
26
public override RateLimiterStatistics ? GetStatistics ( )
Original file line number Diff line number Diff line change 1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
- using System ;
5
4
using System . Collections . Generic ;
6
5
using System . Linq ;
7
- using System . Text ;
8
6
using System . Threading . Tasks ;
9
7
using Xunit ;
10
8
@@ -55,6 +53,20 @@ public async Task DisposeAsyncMakesMethodsThrow()
55
53
await Assert . ThrowsAsync < ObjectDisposedException > ( async ( ) => await chainedLimiter . AcquireAsync ( ) ) ;
56
54
}
57
55
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
+
58
70
[ Fact ]
59
71
public void GetStatisticsReturnsLowestOrAggregateValues ( )
60
72
{
Original file line number Diff line number Diff line change 1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
- using System ;
5
4
using System . Collections . Generic ;
6
5
using System . Linq ;
7
- using System . Text ;
8
6
using System . Threading . Tasks ;
9
7
using Xunit ;
10
8
@@ -89,6 +87,25 @@ public async Task DisposeAsyncMakesMethodsThrow()
89
87
await Assert . ThrowsAsync < ObjectDisposedException > ( async ( ) => await chainedLimiter . AcquireAsync ( "" ) ) ;
90
88
}
91
89
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
+
92
109
[ Fact ]
93
110
public void GetStatisticsReturnsLowestOrAggregateValues ( )
94
111
{
You can’t perform that action at this time.
0 commit comments