Skip to content

[RUM-3845] Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests at DatadogEventListenerTest#2430

Merged
satween merged 2 commits into
developfrom
tvaleev/rum-3845/getting_rid_from_system_time
Dec 5, 2024
Merged

[RUM-3845] Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests at DatadogEventListenerTest#2430
satween merged 2 commits into
developfrom
tvaleev/rum-3845/getting_rid_from_system_time

Conversation

@satween

@satween satween commented Dec 4, 2024

Copy link
Copy Markdown
Contributor

What does this PR do?

In this PR we are trying to get rid of Thread.sleep instructions inside DatadogEventListenerTest.kt.
To do so we use sdkCore.time.deviceTimeNs at DatadogEventListener.kt instead of System.nanoTime() method which let us mock time values

Motivation

This approach makes this test independent from CI machine time and should increase test stability

Additional Notes

This is a WIP PR so changes could be non-final.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@satween
satween force-pushed the tvaleev/rum-3845/getting_rid_from_system_time branch from e014a31 to c33cee3 Compare December 4, 2024 17:41
@satween satween changed the title Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests [RUM-3845] Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests Dec 4, 2024
@codecov-commenter

codecov-commenter commented Dec 4, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.12%. Comparing base (4f55776) to head (a422e7f).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2430   +/-   ##
========================================
  Coverage    70.12%   70.12%           
========================================
  Files          769      769           
  Lines        28504    28505    +1     
  Branches      4774     4774           
========================================
+ Hits         19986    19987    +1     
+ Misses        7183     7173   -10     
- Partials      1335     1345   +10     
Files with missing lines Coverage Δ
...com/datadog/android/okhttp/DatadogEventListener.kt 96.10% <100.00%> (-0.05%) ⬇️

... and 35 files with indirect coverage changes

Comment on lines +247 to +248
assertThat(timing.downloadStart).isGreaterThanOrEqualTo(SHORT_SLEEP_NS)
assertThat(timing.downloadDuration).isGreaterThanOrEqualTo(SHORT_SLEEP_NS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Now that the timing value that is seen by the tested class are fixed and not flaky, we can use a strict equality assertion (.isEqualTo()) instead of a flaky inequality (.isGreaterThanOrEqualTo())

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.

good notice 👍

@satween
satween force-pushed the tvaleev/rum-3845/getting_rid_from_system_time branch from 07003a7 to a422e7f Compare December 5, 2024 10:17
@satween
satween marked this pull request as ready for review December 5, 2024 10:17
@satween
satween requested review from a team as code owners December 5, 2024 10:17
@satween
satween requested a review from xgouchet December 5, 2024 10:17

@0xnm 0xnm left a comment

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.

nice change!

side note: while the ticket itself mentions only a single class, I guess its point is to do similar change in other classes as well, mainly in the RUM scopes related-classes and their tests; so the title of this PR can be a bit misleading.

@satween satween changed the title [RUM-3845] Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests [RUM-3845] Trying to get from Thread.sleep(SHORT_SLEEP_MS) in unit tests at DatadogEventListenerTest Dec 5, 2024
@satween

satween commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

nice change!

side note: while the ticket itself mentions only a single class, I guess its point is to do similar change in other classes as well, mainly in the RUM scopes related-classes and their tests; so the title of this PR can be a bit misleading.

Thanks, yep, planning to make similar changes in other places as well.
PR title adjusted.

@satween
satween merged commit b204077 into develop Dec 5, 2024
@satween
satween deleted the tvaleev/rum-3845/getting_rid_from_system_time branch December 5, 2024 13:19
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.

4 participants