Skip to content

Add more resiliency to unit tests#886

Merged
zacharycmontoya merged 10 commits into
masterfrom
zach/ci/test-improvements
Aug 28, 2020
Merged

Add more resiliency to unit tests#886
zacharycmontoya merged 10 commits into
masterfrom
zach/ci/test-improvements

Conversation

@zacharycmontoya

@zacharycmontoya zacharycmontoya commented Aug 28, 2020

Copy link
Copy Markdown
Contributor

Tests affected:

  • Datadog.Trace.Tests.ApiTests.SendTracesAsync_500_ErrorIsCaught
  • Datadog.Trace.Tests.Sampling.RateLimiterTests.Limits_Approximately_To_Defaults

@DataDog/apm-dotnet

…oncurrent tasks, remove unnecessary Thread.Sleep that might be making the overall operations take longer and skew the actual result from the expected result.
@zacharycmontoya zacharycmontoya added the area:tests unit tests, integration tests label Aug 28, 2020
@zacharycmontoya
zacharycmontoya requested a review from a team as a code owner August 28, 2020 02:20
@zacharycmontoya zacharycmontoya self-assigned this Aug 28, 2020
…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.
Comment thread test/Datadog.Trace.Tests/ApiTests.cs Outdated
var expectedLimit = totalMilliseconds * actualIntervalLimit / 1_000;

var acceptableVariance = (actualIntervalLimit * 1.0);
var acceptableVariance = (actualIntervalLimit * 1.15);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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%?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zacharycmontoya zacharycmontoya Aug 28, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lucaspimentel
lucaspimentel requested review from a team and lucaspimentel August 28, 2020 12:58
@zacharycmontoya
zacharycmontoya force-pushed the zach/ci/test-improvements branch from d833e7b to bdf57cc Compare August 28, 2020 17:31
…ew Span or not in the RateLimiter. This removes the need for the ConcurrentQueue entirely."

This reverts commit bdf57cc.
@zacharycmontoya
zacharycmontoya merged commit d95f036 into master Aug 28, 2020
@zacharycmontoya
zacharycmontoya deleted the zach/ci/test-improvements branch August 28, 2020 19:10
@zacharycmontoya zacharycmontoya added this to the 1.19.2 milestone Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tests unit tests, integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants