Esempio n. 1
0
        public void TestDropboxRateLimiter()
        {
            // Set the limit to 60/sec, let it run for 5s
            // Expected count around 300 give or take.
            var rateLimiter = new DropboxHelper.RateLimiter(60, TimeSpan.FromSeconds(1));
            var start = DateTime.Now;
            int total = 0;
            while (DateTime.Now - start <= TimeSpan.FromSeconds(5))
            {
                rateLimiter.Throtte();
                ++total;
            }

            TestTracer.Trace("total = {0}", total);

            // For robustness, allow wider range
            Assert.True(total >= 240, total + " should be >= 240");
            Assert.True(total <= 360, total + " should be <= 360");
        }
Esempio n. 2
0
        public async Task TestDropboxRateLimiter(int limit, int total)
        {
            var interval = 1;
            var rateLimiter = new DropboxHelper.RateLimiter(limit, TimeSpan.FromSeconds(interval));
            var duration = TimeSpan.FromSeconds(total / limit - interval - 0.5);
            var start = DateTime.Now;
            while (--total > 0)
            {
                await rateLimiter.ThrottleAsync();
            }

            // Assert
            var end = DateTime.Now;
            Assert.True((end - start) >= duration, (end - start) + "<" + duration);
        }