Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Add tests for verifying scope changes thread isolation #508

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion sentry-core/src/test/java/io/sentry/core/SentryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package io.sentry.core

import java.io.File
import java.nio.file.Files
import java.util.concurrent.CompletableFuture
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class SentryTest {

@BeforeTest
Expand Down Expand Up @@ -81,6 +82,30 @@ class SentryTest {
assertTrue(sentryOptions!!.serializer is GsonSerializer)
}

@Test
fun `scope changes are isolated to a thread`() {
Sentry.init {
it.dsn = "http://key@localhost/proj"
}
Sentry.configureScope {
it.setTag("a", "a")
}

CompletableFuture.runAsync {
Sentry.configureScope {
it.setTag("b", "b")
}

Sentry.configureScope {
assertEquals(setOf("a", "b"), it.tags.keys)
}
}.get()

Sentry.configureScope {
assertEquals(setOf("a"), it.tags.keys)
}
}

private fun getTempPath(): String {
val tempFile = Files.createTempDirectory("cache").toFile()
tempFile.delete()
Expand Down