-
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...n-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/ReplayTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.sentry.uitest.android | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.test.core.app.launchActivity | ||
import io.sentry.SentryOptions | ||
import leakcanary.LeakAssertions | ||
import leakcanary.LeakCanary | ||
import org.awaitility.kotlin.await | ||
import shark.AndroidReferenceMatchers | ||
import shark.IgnoredReferenceMatcher | ||
import shark.ReferencePattern | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import kotlin.test.Test | ||
|
||
class ReplayTest : BaseUiTest() { | ||
@Test | ||
fun composeReplayDoesNotLeak() { | ||
val sent = AtomicBoolean(false) | ||
|
||
LeakCanary.config = LeakCanary.config.copy( | ||
referenceMatchers = AndroidReferenceMatchers.appDefaults + | ||
listOf( | ||
IgnoredReferenceMatcher( | ||
ReferencePattern.InstanceFieldPattern( | ||
"com.saucelabs.rdcinjector.testfairy.TestFairyEventQueue", | ||
"context" | ||
) | ||
), | ||
// Seems like a false-positive returned by LeakCanary when curtains is used in | ||
// the host application (LeakCanary uses it itself internally). We use kind of | ||
// the same approach which possibly clashes with LeakCanary's internal state. | ||
// Only the case when replay is enabled. | ||
// TODO: check if it's actually a leak on our side, or a false-positive and report to LeakCanary's github issue tracker | ||
IgnoredReferenceMatcher( | ||
ReferencePattern.InstanceFieldPattern( | ||
"curtains.internal.RootViewsSpy", | ||
"delegatingViewList" | ||
) | ||
) | ||
) + ('a'..'z').map { char -> | ||
IgnoredReferenceMatcher( | ||
ReferencePattern.StaticFieldPattern( | ||
"com.testfairy.modules.capture.TouchListener", | ||
"$char" | ||
) | ||
) | ||
} | ||
) | ||
|
||
val activityScenario = launchActivity<ComposeActivity>() | ||
activityScenario.moveToState(Lifecycle.State.RESUMED) | ||
|
||
initSentry { | ||
it.experimental.sessionReplay.sessionSampleRate = 1.0 | ||
|
||
it.beforeSendReplay = | ||
SentryOptions.BeforeSendReplayCallback { event, _ -> | ||
sent.set(true) | ||
event | ||
} | ||
} | ||
|
||
// wait until first segment is being sent | ||
await.untilTrue(sent) | ||
|
||
activityScenario.moveToState(Lifecycle.State.DESTROYED) | ||
|
||
LeakAssertions.assertNoLeaks() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters