Skip to content

Commit 66a6c33

Browse files
committed
fix test
1 parent 0179ea3 commit 66a6c33

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

sentry-async-profiler/src/test/java/io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverterTest.kt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.asyncprofiler.convert
22

3+
import io.sentry.DateUtils
34
import io.sentry.ILogger
45
import io.sentry.IProfileConverter
56
import io.sentry.IScope
@@ -12,7 +13,12 @@ import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
1213
import io.sentry.protocol.profiling.SentryProfile
1314
import io.sentry.test.DeferredExecutorService
1415
import java.io.IOException
16+
import java.time.LocalDateTime
17+
import java.time.ZoneOffset
18+
import java.time.temporal.ChronoUnit
19+
import java.util.*
1520
import kotlin.io.path.Path
21+
import kotlin.math.absoluteValue
1622
import kotlin.test.AfterTest
1723
import kotlin.test.BeforeTest
1824
import 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

Comments
 (0)