|
| 1 | +import io.sentry.ILogger |
| 2 | +import io.sentry.ISentryExecutorService |
| 3 | +import io.sentry.NoOpContinuousProfiler |
| 4 | +import io.sentry.NoOpProfileConverter |
| 5 | +import io.sentry.SentryOptions |
| 6 | +import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler |
| 7 | +import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider |
| 8 | +import io.sentry.util.InitUtil |
| 9 | +import kotlin.test.Test |
| 10 | +import org.mockito.kotlin.mock |
| 11 | + |
| 12 | +class AsyncProfilerInitUtilTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + fun `initialize Profiler returns no-op profiler if profiling disabled`() { |
| 16 | + val options = SentryOptions() |
| 17 | + val profiler = InitUtil.initializeProfiler(options) |
| 18 | + assert(profiler is NoOpContinuousProfiler) |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + fun `initialize Converter returns no-op profiler if profiling disabled`() { |
| 23 | + val options = SentryOptions() |
| 24 | + val converter = InitUtil.initializeProfileConverter(options) |
| 25 | + assert(converter is NoOpProfileConverter) |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `initialize Profiler returns no-op profiler if profiler already initialized`() { |
| 30 | + val options = |
| 31 | + SentryOptions().also { |
| 32 | + it.setProfileSessionSampleRate(1.0) |
| 33 | + it.tracesSampleRate = 1.0 |
| 34 | + it.setContinuousProfiler( |
| 35 | + JavaContinuousProfiler(mock<ILogger>(), "", 10, mock<ISentryExecutorService>()) |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + val profiler = InitUtil.initializeProfiler(options) |
| 40 | + assert(profiler is NoOpContinuousProfiler) |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + fun `initialize converter returns no-op converter if converter already initialized`() { |
| 45 | + val options = |
| 46 | + SentryOptions().also { |
| 47 | + it.setProfileSessionSampleRate(1.0) |
| 48 | + it.tracesSampleRate = 1.0 |
| 49 | + it.profilerConverter = AsyncProfilerProfileConverterProvider.AsyncProfilerProfileConverter() |
| 50 | + } |
| 51 | + |
| 52 | + val converter = InitUtil.initializeProfileConverter(options) |
| 53 | + assert(converter is NoOpProfileConverter) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun `initialize Profiler returns JavaContinuousProfiler if profiling enabled but profiler not yet initialized`() { |
| 58 | + val options = |
| 59 | + SentryOptions().also { |
| 60 | + it.setProfileSessionSampleRate(1.0) |
| 61 | + it.tracesSampleRate = 1.0 |
| 62 | + } |
| 63 | + val profiler = InitUtil.initializeProfiler(options) |
| 64 | + assert(profiler is JavaContinuousProfiler) |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + fun `initialize Profiler returns AsyncProfilerProfileConverterProvider if profiling enabled but profiler not yet initialized`() { |
| 69 | + val options = |
| 70 | + SentryOptions().also { |
| 71 | + it.setProfileSessionSampleRate(1.0) |
| 72 | + it.tracesSampleRate = 1.0 |
| 73 | + } |
| 74 | + val converter = InitUtil.initializeProfileConverter(options) |
| 75 | + assert(converter is AsyncProfilerProfileConverterProvider.AsyncProfilerProfileConverter) |
| 76 | + } |
| 77 | +} |
0 commit comments