Add more resiliency to unit tests#886
Conversation
…oncurrent tasks, remove unnecessary Thread.Sleep that might be making the overall operations take longer and skew the actual result from the expected result.
…ronize concurrent tasks, remove unnecessary Thread.Sleep that might be making the overall operations take longer and skew the actual result from the expected result." This reverts commit cb3ca9f.
| var expectedLimit = totalMilliseconds * actualIntervalLimit / 1_000; | ||
|
|
||
| var acceptableVariance = (actualIntervalLimit * 1.0); | ||
| var acceptableVariance = (actualIntervalLimit * 1.15); |
There was a problem hiding this comment.
Is it possible that test failures here are real and that we should improve the rate limiting logic? Or are we ok with rate limits to be exceeded by 15%?
There was a problem hiding this comment.
It's possible that 1) the rate limiter is not performing as we expect, 2) the timing calculations in this test are incorrect, or 3) our testing variance is too small. I'm going to look into 1 and 2 today
There was a problem hiding this comment.
My current suspicion is that the RateLimiter is misbehaving. We build up a queue to hold onto timestamps from the last window, where the max size should be about the same as the configured interval limit. However, when one thread is busy dequeuing that as part of the refresh logic, a bunch of other threads may be trying to push Spans for the new window, and the queue toggles from full to not full. However, that's not the right indicator for the new window, so I'm trying to use the _windowAllowed value as the signal instead of queue size.
There was a problem hiding this comment.
In retrospect, it seems like there is just a mismatch of the expected test output and the current rate limit implementation. In our tests we simply assume that we should see the number of allowed spans = intervalLimit * numberOfIntervals. But that doesn't take into account the behavior I just described. So one of the two should change, either the implementation or the test expectations
There was a problem hiding this comment.
Talking offline, we'll allow for more tolerance on the lower limit side. This aligns with the reality that our current implementation of the rate limiter dequeues from the rolling window is slower than enqueueing to the rolling window, which may result in a fewer number of Allowed spans. This is fine and we'll account for that difference in our test expectations.
…or not in the RateLimiter. This removes the need for the ConcurrentQueue entirely.
d833e7b to
bdf57cc
Compare
…ew Span or not in the RateLimiter. This removes the need for the ConcurrentQueue entirely." This reverts commit bdf57cc.
Tests affected:
Datadog.Trace.Tests.ApiTests.SendTracesAsync_500_ErrorIsCaughtDatadog.Trace.Tests.Sampling.RateLimiterTests.Limits_Approximately_To_Defaults@DataDog/apm-dotnet