@@ -226,32 +226,47 @@ public void ConvertInvariantTest()
226226 }
227227 }
228228
229- [ TestMethod ]
229+ [ ConditionalTestMethod ]
230+ [ PlatformSpecificTest (
231+ ~ TestPlatforms . OSX ,
232+ "Has an issue on MacOS. See https://github.com/dotnet/corefx/issues/42607"
233+ ) ]
230234 public async Task RateGate ( )
231235 {
232- const int timesPerPeriod = 1 ;
233- const int ms = 100 ;
234- const int loops = 5 ;
235- double msMax = ( double ) ms * 1.5 ;
236- double msMin = ( double ) ms * ( 1.0 / 1.5 ) ;
237- RateGate gate = new RateGate ( timesPerPeriod , TimeSpan . FromMilliseconds ( ms ) ) ;
238- if ( ! ( await gate . WaitToProceedAsync ( 0 ) ) )
239- {
240- throw new APIException ( "Rate gate should have allowed immediate access to first attempt" ) ;
241- }
242- for ( int i = 0 ; i < loops ; i ++ )
243- {
244- Stopwatch timer = Stopwatch . StartNew ( ) ;
245- await gate . WaitToProceedAsync ( ) ;
246- timer . Stop ( ) ;
247-
248- if ( i > 0 )
249- {
250- // check for too much elapsed time with a little fudge
251- Assert . IsTrue ( timer . Elapsed . TotalMilliseconds <= msMax , "Rate gate took too long to wait in between calls: " + timer . Elapsed . TotalMilliseconds + "ms" ) ;
252- Assert . IsTrue ( timer . Elapsed . TotalMilliseconds >= msMin , "Rate gate took too little to wait in between calls: " + timer . Elapsed . TotalMilliseconds + "ms" ) ;
253- }
254- }
236+ const int timesPerPeriod = 1 ;
237+ const int ms = 100 ;
238+ const int loops = 5 ;
239+ const double msMax = ( double ) ms * 1.5 ;
240+ const double msMin = ( double ) ms * ( 1.0 / 1.5 ) ;
241+ var gate = new RateGate ( timesPerPeriod , TimeSpan . FromMilliseconds ( ms ) ) ;
242+
243+ var entered = await gate . WaitToProceedAsync ( 0 ) ;
244+ if ( ! entered )
245+ {
246+ throw new APIException ( "Rate gate should have allowed immediate access to first attempt" ) ;
247+ }
248+
249+ for ( var i = 0 ; i < loops ; i ++ )
250+ {
251+ var timer = Stopwatch . StartNew ( ) ;
252+ await gate . WaitToProceedAsync ( ) ;
253+ timer . Stop ( ) ;
254+
255+ if ( i <= 0 )
256+ {
257+ continue ;
258+ }
259+
260+ // check for too much elapsed time with a little fudge
261+ Assert . IsTrue (
262+ timer . Elapsed . TotalMilliseconds <= msMax ,
263+ "Rate gate took too long to wait in between calls: " + timer . Elapsed . TotalMilliseconds + "ms"
264+ ) ;
265+ Assert . IsTrue (
266+ timer . Elapsed . TotalMilliseconds >= msMin ,
267+ "Rate gate took too little to wait in between calls: " + timer . Elapsed . TotalMilliseconds + "ms"
268+ ) ;
269+ }
255270 }
256271 }
257- }
272+ }
0 commit comments