-
-
Notifications
You must be signed in to change notification settings - Fork 472
chore(android-sqlite): Repair start times of spans generated by SentrySQLiteDriver #5543
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d18e1c
chore(android-sqlite): Repair start times of spans generated by Sentr…
0xadam-brown 3eb3a3f
Make repair method internal + add unit tests
0xadam-brown 776deac
SQLiteSpanInstrumentation.startTimestamp() now returns Long + skips S…
0xadam-brown fee2461
Rename childStartTimestampOrNull() -> computeNanoStartTimestampForChi…
0xadam-brown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ry-android-sqlite/src/test/java/io/sentry/sqlite/ComputeNanoStartTimestampForChildTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package io.sentry.sqlite | ||
|
|
||
| import io.sentry.DateUtils | ||
| import io.sentry.ISpan | ||
| import io.sentry.SentryLongDate | ||
| import io.sentry.SentryNanotimeDate | ||
| import java.util.Date | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
| import kotlin.test.assertTrue | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.whenever | ||
|
|
||
| class ComputeNanoStartTimestampForChildTest { | ||
|
|
||
| @Test | ||
| fun `returns parent wall clock plus elapsed monotonic time since parent started`() { | ||
| val wallClockMillis = 1_000_000L | ||
| val elapsedNanos = 500_000L | ||
| val parentMonotonicNanos = System.nanoTime() - elapsedNanos | ||
| val span = spanWithNanotimeStart(wallClockMillis, parentMonotonicNanos) | ||
|
|
||
| val timestamp = span.computeNanoStartTimestampForChild()!! | ||
|
|
||
| val elapsedSinceParentStart = timestamp - DateUtils.millisToNanos(wallClockMillis) | ||
| assertTrue(elapsedSinceParentStart >= elapsedNanos) | ||
| assertTrue(elapsedSinceParentStart < elapsedNanos + TEST_SLACK_NANOS) | ||
| } | ||
|
|
||
| @Test | ||
| fun `same millisecond wall clocks with different monotonic offsets produce distinct ordered timestamps`() { | ||
| val wallClockMillis = 1_000_000L | ||
| val wallClockNanos = DateUtils.millisToNanos(wallClockMillis) | ||
| val earlierParentMonotonicNanos = System.nanoTime() - 200_000L | ||
| val laterParentMonotonicNanos = System.nanoTime() - 800_000L | ||
| val earlierSpan = spanWithNanotimeStart(wallClockMillis, earlierParentMonotonicNanos) | ||
| val laterSpan = spanWithNanotimeStart(wallClockMillis, laterParentMonotonicNanos) | ||
|
|
||
| assertEquals( | ||
| earlierSpan.startDate.nanoTimestamp(), | ||
| laterSpan.startDate.nanoTimestamp(), | ||
| "Raw parent timestamps share the same ms-quantized value", | ||
| ) | ||
|
|
||
| val earlier = earlierSpan.computeNanoStartTimestampForChild()!! | ||
| val later = laterSpan.computeNanoStartTimestampForChild()!! | ||
|
|
||
| assertTrue(earlier > wallClockNanos) | ||
| assertTrue(later > wallClockNanos) | ||
| assertTrue(earlier < later) | ||
| assertTrue(later - earlier >= 500_000L) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns parent wall clock when no monotonic time has elapsed since parent started`() { | ||
| val wallClockMillis = 1_000_000L | ||
| val parentMonotonicNanos = System.nanoTime() | ||
| val span = spanWithNanotimeStart(wallClockMillis, parentMonotonicNanos) | ||
|
|
||
| val elapsedSinceParentStart = | ||
| span.computeNanoStartTimestampForChild()!! - DateUtils.millisToNanos(wallClockMillis) | ||
| assertTrue(elapsedSinceParentStart >= 0L) | ||
| assertTrue(elapsedSinceParentStart < TEST_SLACK_NANOS) | ||
| } | ||
|
|
||
| @Test | ||
| fun `works when parent wall clock differs from millisecond baseline`() { | ||
| val wallClockMillis = 1_000_001L | ||
| val elapsedNanos = 1_500_000L | ||
| val parentMonotonicNanos = System.nanoTime() - elapsedNanos | ||
| val span = spanWithNanotimeStart(wallClockMillis, parentMonotonicNanos) | ||
|
|
||
| val elapsedSinceParentStart = | ||
| span.computeNanoStartTimestampForChild()!! - DateUtils.millisToNanos(wallClockMillis) | ||
| assertTrue(elapsedSinceParentStart >= elapsedNanos) | ||
| assertTrue(elapsedSinceParentStart < elapsedNanos + TEST_SLACK_NANOS) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns null when start date is not SentryNanotimeDate`() { | ||
| val span = mock<ISpan>() | ||
| whenever(span.startDate).thenReturn(SentryLongDate(DateUtils.millisToNanos(1_000_000L))) | ||
|
|
||
| assertNull(span.computeNanoStartTimestampForChild()) | ||
| } | ||
|
|
||
| private fun spanWithNanotimeStart(wallClockMillis: Long, parentMonotonicNanos: Long): ISpan { | ||
| val startDate = SentryNanotimeDate(Date(wallClockMillis), parentMonotonicNanos) | ||
| val span = mock<ISpan>() | ||
| whenever(span.startDate).thenReturn(startDate) | ||
| return span | ||
| } | ||
|
|
||
| companion object { | ||
|
|
||
| // Upper bound for monotonic drift while the test body runs. | ||
| private const val TEST_SLACK_NANOS = 50_000_000L | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.