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

[NO-TICKET] automatically trace with correct time even when time is stubbed by timecop #185

Merged
merged 4 commits into from
May 30, 2024

Conversation

anmarchenko
Copy link
Member

What does this PR do?
timecop is a popular gem that is used to mock time in tests. It works by replacing Time.now method and aliasing the original as now_without_mock_time.

This creates issues with tests tracing as reported spans has invalid time and thus are being skipped or reported with wrong timestamps.

It is possible to setup time_now_provider in settings: we can do this automatically when activating CI mode so that no manual work from user's side is needed.

Motivation
We received multiple customer support issues related to invalid start_time.

How to test the change?
Unit tests are provided (with timecop dependency).

Verified

This commit was signed with the committer’s verified signature.
anmarchenko Andrey Marchenko
…w_provider to Time.now_without_mock_time
@anmarchenko anmarchenko requested review from a team as code owners May 29, 2024 15:00
@anmarchenko anmarchenko changed the title [NO-TICKET] automatically trace with correct time even when timecop mocked time [NO-TICKET] automatically trace with correct time even when time is stubbed by timecop May 29, 2024
@anmarchenko
Copy link
Member Author

Fun fact: it broke my tests that use Timecop as well! this means it works

Verified

This commit was signed with the committer’s verified signature.
anmarchenko Andrey Marchenko

Verified

This commit was signed with the committer’s verified signature.
anmarchenko Andrey Marchenko

Verified

This commit was signed with the committer’s verified signature.
anmarchenko Andrey Marchenko
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 97.05882% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 98.93%. Comparing base (cbf442b) to head (4fa4efb).

Files Patch % Lines
lib/datadog/ci/configuration/components.rb 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
- Coverage   98.94%   98.93%   -0.01%     
==========================================
  Files         220      221       +1     
  Lines       10009    10034      +25     
  Branches      464      466       +2     
==========================================
+ Hits         9903     9927      +24     
- Misses        106      107       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anmarchenko anmarchenko merged commit b997340 into main May 30, 2024
26 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/timecop_time_provider_config branch May 30, 2024 16:53
@github-actions github-actions bot added this to the 1.0.0 milestone May 30, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants