Skip to content

Commit

Permalink
Merge d4a35bb into 06db228
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed May 2, 2024
2 parents 06db228 + d4a35bb commit dd4548a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private Sentry() {}
*/
// TODO [HSM] use SentryOptions.empty and address
// https://github.com/getsentry/sentry-java/issues/2541
private static volatile @NotNull IScope globalScope = new Scope(SentryOptions.empty());
private static final @NotNull IScope globalScope = new Scope(SentryOptions.empty());

/** Default value for globalHubMode is false */
private static final boolean GLOBAL_HUB_DEFAULT_MODE = false;
Expand Down Expand Up @@ -277,12 +277,12 @@ private static synchronized void init(
final IScopes scopes = getCurrentScopes();
final IScope rootScope = new Scope(options);
final IScope rootIsolationScope = new Scope(options);
globalScope.bindClient(new SentryClient(options));
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");

getScopesStorage().set(rootScopes);

scopes.close(true);
globalScope.bindClient(new SentryClient(options));

// If the executorService passed in the init is the same that was previously closed, we have to
// set a new one
Expand Down
32 changes: 32 additions & 0 deletions sentry/src/test/java/io/sentry/SentryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ class SentryTest {
verify(scopes).close(eq(true))
}

@Test
fun `global client is enabled after restart`() {
val scopes = mock<IScopes>()
whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() }
whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() }

Sentry.init {
it.dsn = dsn
}
Sentry.setCurrentScopes(scopes)
Sentry.init {
it.dsn = dsn
}
verify(scopes).close(eq(true))
assertTrue(Sentry.getGlobalScope().client.isEnabled)
}

@Test
fun `global client is disabled after close`() {
val scopes = mock<IScopes>()
whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() }
whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() }

Sentry.init {
it.dsn = dsn
}
Sentry.setCurrentScopes(scopes)
Sentry.close()
verify(scopes).close(eq(false))
assertFalse(Sentry.getGlobalScope().client.isEnabled)
}

@Test
fun `close calls scopes close with isRestarting false`() {
val scopes = mock<IScopes>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import org.mockito.kotlin.check
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import kotlin.test.BeforeTest
import kotlin.test.Test

class MetricsIntegrationTest {

@BeforeTest
fun setup() {
Sentry.close()
}

@Test
fun `metrics are collected`() {
val options = SentryOptions().apply {
Expand Down

0 comments on commit dd4548a

Please sign in to comment.