Exemplo n.º 1
0
        public async Task Should_allow_dynamic_reconfiguration_down()
        {
            var router = new CommandRouter();
            int count  = 0;
            IPipe <InputContext> pipe = Pipe.New <InputContext>(cfg =>
            {
                cfg.UseRateLimit(100, TimeSpan.FromSeconds(1), router);
                cfg.UseExecute(cxt =>
                {
                    Interlocked.Increment(ref count);
                });
            });

            await router.SetRateLimit(10);

            var context = new InputContext("Hello");

            var timer = Stopwatch.StartNew();

            Task[] tasks = Enumerable.Range(0, 101)
                           .Select(index => Task.Run(async() => await pipe.Send(context)))
                           .ToArray();

            await Task.WhenAll(tasks);

            timer.Stop();

            Assert.That(timer.ElapsedMilliseconds, Is.GreaterThan(9500));
        }