Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: duration calculation #94

Closed
gregkalapos opened this issue Feb 6, 2019 · 1 comment
Closed

Bug: duration calculation #94

gregkalapos opened this issue Feb 6, 2019 · 1 comment
Assignees

Comments

@gregkalapos
Copy link
Contributor

We have sometimes failing tests like this:

Error
Expected 9 to be greater or equal to: 10
Expected: True
Actual: False
Stacktrace
at Elastic.Apm.Tests.ApiTests.ConvenientApiTransactionTests.AssertWith1TransactionAsync(Func`2 func) in /var/lib/jenkins/workspace/tnet_apm-agent-dotnet-mbp_master/src/github.com/elastic/apm-agent-dotnet/test/Elastic.Apm.Tests/ApiTests/ConvenientApiTransactionTests.cs:line 487
at Elastic.Apm.Tests.ApiTests.ConvenientApiTransactionTests.AsyncTaskWithReturnType() in /var/lib/jenkins/workspace/tnet_apm-agent-dotnet-mbp_master/src/github.com/elastic/apm-agent-dotnet/test/Elastic.Apm.Tests/ApiTests/ConvenientApiTransactionTests.cs:line 265
--- End of stack trace from previous location where exception was thrown ---

This is the assert:

var duration = payloadSender.FirstTransaction.Duration;
Assert.True(duration >= SleepLength, $"Expected {duration} to be greater or equal to: {SleepLength}");

This is how we calculate the duration (very very bad!):
if (!Duration.HasValue) Duration = (long)(DateTimeOffset.UtcNow - Start).TotalMilliseconds;

We have a little bit of a data type chaos here and we should heavily overthink this! - also we should see what datatypes other agents use for duration and probably stick with that, but each time we convert we should be more careful.

@gregkalapos
Copy link
Contributor Author

gregkalapos commented Feb 13, 2019

We have 2 problems here:

  • The Duration on ITransaction is a long, but the Duration on the ISpan is a double. This was clearly not intentional. The java agent uses double and the .TotalMilliseconds is also a double, so we stick to double for duration in the .NET Agent.

  • The other problem is that we use 10ms for these tests, but that's probably lower than the resolution of the timer used by await Task.Delay(), so it's impossible to await exactly 10ms (it can be 9,5ms). https://stackoverflow.com/a/31742754/1783306 To solve this I'll increase the waits to 20ms (I think 15ms is the resolution). Due to this inaccuracy we enable 10% error in the tests. More on Fix failing API tests - again #104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants