Skip to content

Commit 3d90c07

Browse files
committed
fixed tests
1 parent 0cce8e9 commit 3d90c07

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private void updateCache() {
396396
if (!isUpdatingCache.getAndSet(true)) {
397397
// Fallback: query current active network in the background
398398
if (options.getThreadChecker().isMainThread()) {
399-
submitSafe(() -> updateCacheFromConnectivityManager());
399+
submitSafe(() -> updateCacheFromConnectivityManager(), () -> isUpdatingCache.set(false));
400400
} else {
401401
updateCacheFromConnectivityManager();
402402
}
@@ -854,12 +854,20 @@ public static List<NetworkCallback> getChildCallbacks() {
854854
}
855855

856856
private void submitSafe(@NotNull Runnable r) {
857+
submitSafe(r, null);
858+
}
859+
860+
private void submitSafe(final @NotNull Runnable r, final @Nullable Runnable onFinally) {
857861
try {
858862
options.getExecutorService().submit(r);
859863
} catch (Throwable e) {
860864
options
861865
.getLogger()
862866
.log(SentryLevel.ERROR, "AndroidConnectionStatusProvider submit failed", e);
867+
} finally {
868+
if (onFinally != null) {
869+
onFinally.run();
870+
}
863871
}
864872
}
865873
}

sentry-android-core/src/test/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProviderTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class AndroidConnectionStatusProviderTest {
106106
options = SentryOptions()
107107
options.setLogger(logger)
108108
options.executorService = ImmediateExecutorService()
109+
options.threadChecker = AndroidThreadChecker.getInstance()
109110

110111
// Reset current time for each test to ensure cache isolation
111112
currentTime = 1000L
@@ -128,6 +129,7 @@ class AndroidConnectionStatusProviderTest {
128129

129130
@AfterTest
130131
fun `tear down`() {
132+
options.executorService = ImmediateExecutorService()
131133
// clear the cache and ensure proper cleanup
132134
connectionStatusProvider.close()
133135
contextUtilsStaticMock.close()

0 commit comments

Comments
 (0)