public void Throttle_for_various_cost_elements_must_burst_some_elements_if_have_enough_time()
{
this.AssertAllStagesStopped(() =>
{
var upstream = TestPublisher.CreateProbe<int>(this);
var downstream = TestSubscriber.CreateProbe<int>(this);
Source.FromPublisher(upstream)
.Throttle(2, TimeSpan.FromMilliseconds(400), 5, e => e < 4 ? 1 : 20, ThrottleMode.Shaping)
.RunWith(Sink.FromSubscriber(downstream), Materializer);
downstream.Request(1);
upstream.SendNext(1);
downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
downstream.ExpectNext(1);
downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); //wait to receive 2 in burst afterwards
downstream.Request(5);
var expected = new List<OnNext>();
for (var i = 2; i < 5; i++)
{
upstream.SendNext(i);
if (i < 4)
expected.Add(new OnNext(i));
}
downstream.ReceiveWhile(TimeSpan.FromMilliseconds(200), filter: x => x, msgs: 2)
.ShouldAllBeEquivalentTo(expected);
downstream.Cancel();
}, Materializer);
}