11package io.sentry.asyncprofiler.convert
22
3+ import io.sentry.DateUtils
34import io.sentry.ILogger
45import io.sentry.IProfileConverter
56import io.sentry.IScope
@@ -12,7 +13,12 @@ import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
1213import io.sentry.protocol.profiling.SentryProfile
1314import io.sentry.test.DeferredExecutorService
1415import java.io.IOException
16+ import java.time.LocalDateTime
17+ import java.time.ZoneOffset
18+ import java.time.temporal.ChronoUnit
19+ import java.util.*
1520import kotlin.io.path.Path
21+ import kotlin.math.absoluteValue
1622import kotlin.test.AfterTest
1723import kotlin.test.BeforeTest
1824import kotlin.test.assertEquals
@@ -159,22 +165,21 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
159165 val samples = sentryProfile.samples
160166 assertTrue(samples.isNotEmpty())
161167
162- // Verify timestamps are in seconds with proper decimal places
163- samples.forEach { sample ->
164- val timestamp = sample.timestamp
165- assertTrue(timestamp > 0 , " Timestamp should be positive" )
166- // No need to check exact decimal places as this depends on JFR precision
167- assertTrue(
168- timestamp < System .currentTimeMillis() / 1000.0 + 360 ,
169- " Timestamp should be recent" ,
170- )
171- }
168+ val minTimestamp = samples.minOf { it.timestamp }
169+ val maxTimestamp = samples.maxOf { it.timestamp }
170+ val sampleTimeStamp =
171+ DateUtils .nanosToDate((maxTimestamp * 1000 * 1000 * 1000 ).toLong()).toInstant()
172172
173- if (samples.isNotEmpty()) {
174- val minTimestamp = samples.minOf { it.timestamp }
175- val maxTimestamp = samples.maxOf { it.timestamp }
176- assertTrue(maxTimestamp >= minTimestamp, " Max timestamp should be >= min timestamp" )
177- }
173+ // The sample was recorded around "2025-09-05T08:14:50" in UTC timezone
174+ val referenceTimestamp = LocalDateTime .parse(" 2025-09-05T08:14:50" ).toInstant(ZoneOffset .UTC )
175+ val between = ChronoUnit .MILLIS .between(sampleTimeStamp, referenceTimestamp).absoluteValue
176+
177+ assertTrue(between < 5000 , " Sample timestamp should be within 5s of reference timestamp" )
178+ assertTrue(maxTimestamp >= minTimestamp, " Max timestamp should be >= min timestamp" )
179+ assertTrue(
180+ maxTimestamp - minTimestamp <= 10 ,
181+ " There should be a max difference of <10s between min and max timestamp" ,
182+ )
178183 }
179184
180185 @Test
0 commit comments