示例#1
0
        /// <summary>
        /// Tests the WaitAndRun function with a QuotaGrate and the bucketed API endpoint.
        /// </summary>
        /// <returns>Whether or not the test was successful along with the response.</returns>
        private static TestResult TestWaitAndRun()
        {
            const int bucketSize = 5;
            const int expirationTime = 5000;
            var getRoute = $"/ratetest/get/bucketed/TestWaitAndRun/{bucketSize}/{expirationTime}";
            var evalRoute = $"/ratetest/eval/bucketed/TestWaitAndRun/{bucketSize}/{expirationTime}";
            var clearRoute = $"/ratetest/clear/bucketed/TestWaitAndRun/{bucketSize}/{expirationTime}";

            Get(clearRoute);
            var grate = new QuotaGrate<string>(bucketSize, TimeSpan.FromMilliseconds(expirationTime));
            var token = "demoToken";

            for (var i = 0; i < 10; i++)
            {
                grate.WaitAndRun(token, new Task<string>(() => Get(getRoute))).Wait();
            }

            // @todo timing check here
            return GetAsBool(evalRoute);
        }
示例#2
0
        /// <summary>
        /// Tests the Quota grate with the basic API endpoint.
        /// </summary>
        /// <returns>Whether or not the test was successful along with the response.</returns>
        private static TestResult TestQuotaGrateWithSimple()
        {
            const int timeout = 500;
            var getRoute = $"/ratetest/get/simple/TestQuotaGrateWithSimple/{timeout}";
            var evalRoute = $"/ratetest/eval/simple/TestQuotaGrateWithSimple/{timeout}";
            var clearRoute = $"/ratetest/clear/simple/TestQuotaGrateWithSimple/{timeout}";
            var token = "demoToken";

            Get(clearRoute);
            var grate = new QuotaGrate<string>(1, TimeSpan.FromMilliseconds(timeout));

            for (var i = 0; i < 10; i++)
            {
                grate.Wait(token);
                Get(getRoute);
                grate.Release(token);
            }

            // @todo timing check here
            return GetAsBool(evalRoute);
        }