-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hub restore in async wrappers (#3225)
* fix hub restoration point in wrappers: SentryWrapper, SentryTaskDecorator and SentryScheduleHook * add changelog * fix SentryScheduleHook in jakarta, api dump * Update CHANGELOG.md Co-authored-by: Alexander Dinauer <[email protected]> * code review --------- Co-authored-by: Alexander Dinauer <[email protected]>
- Loading branch information
Showing
11 changed files
with
330 additions
and
10 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
59 changes: 59 additions & 0 deletions
59
sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.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,59 @@ | ||
package io.sentry.spring.jakarta | ||
|
||
import io.sentry.Sentry | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class SentryTaskDecoratorTest { | ||
private val dsn = "http://key@localhost/proj" | ||
private lateinit var executor: ExecutorService | ||
|
||
@BeforeTest | ||
fun beforeTest() { | ||
executor = Executors.newSingleThreadExecutor() | ||
} | ||
|
||
@AfterTest | ||
fun afterTest() { | ||
Sentry.close() | ||
executor.shutdown() | ||
} | ||
|
||
@Test | ||
fun `hub is reset to its state within the thread after decoration is done`() { | ||
Sentry.init { | ||
it.dsn = dsn | ||
} | ||
|
||
val sut = SentryTaskDecorator() | ||
|
||
val mainHub = Sentry.getCurrentHub() | ||
val threadedHub = Sentry.getCurrentHub().clone() | ||
|
||
executor.submit { | ||
Sentry.setCurrentHub(threadedHub) | ||
}.get() | ||
|
||
assertEquals(mainHub, Sentry.getCurrentHub()) | ||
|
||
val callableFuture = | ||
executor.submit( | ||
sut.decorate { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertNotEquals(threadedHub, Sentry.getCurrentHub()) | ||
} | ||
) | ||
|
||
callableFuture.get() | ||
|
||
executor.submit { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertEquals(threadedHub, Sentry.getCurrentHub()) | ||
}.get() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.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,60 @@ | ||
package io.sentry.spring.jakarta.webflux | ||
|
||
import io.sentry.Sentry | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class SentryScheduleHookTest { | ||
|
||
private val dsn = "http://key@localhost/proj" | ||
private lateinit var executor: ExecutorService | ||
|
||
@BeforeTest | ||
fun beforeTest() { | ||
executor = Executors.newSingleThreadExecutor() | ||
} | ||
|
||
@AfterTest | ||
fun afterTest() { | ||
Sentry.close() | ||
executor.shutdown() | ||
} | ||
|
||
@Test | ||
fun `hub is reset to its state within the thread after hook is done`() { | ||
Sentry.init { | ||
it.dsn = dsn | ||
} | ||
|
||
val sut = SentryScheduleHook() | ||
|
||
val mainHub = Sentry.getCurrentHub() | ||
val threadedHub = Sentry.getCurrentHub().clone() | ||
|
||
executor.submit { | ||
Sentry.setCurrentHub(threadedHub) | ||
}.get() | ||
|
||
assertEquals(mainHub, Sentry.getCurrentHub()) | ||
|
||
val callableFuture = | ||
executor.submit( | ||
sut.apply { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertNotEquals(threadedHub, Sentry.getCurrentHub()) | ||
} | ||
) | ||
|
||
callableFuture.get() | ||
|
||
executor.submit { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertEquals(threadedHub, Sentry.getCurrentHub()) | ||
}.get() | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.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,59 @@ | ||
package io.sentry.spring | ||
|
||
import io.sentry.Sentry | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class SentryTaskDecoratorTest { | ||
private val dsn = "http://key@localhost/proj" | ||
private lateinit var executor: ExecutorService | ||
|
||
@BeforeTest | ||
fun beforeTest() { | ||
executor = Executors.newSingleThreadExecutor() | ||
} | ||
|
||
@AfterTest | ||
fun afterTest() { | ||
Sentry.close() | ||
executor.shutdown() | ||
} | ||
|
||
@Test | ||
fun `hub is reset to its state within the thread after decoration is done`() { | ||
Sentry.init { | ||
it.dsn = dsn | ||
} | ||
|
||
val sut = SentryTaskDecorator() | ||
|
||
val mainHub = Sentry.getCurrentHub() | ||
val threadedHub = Sentry.getCurrentHub().clone() | ||
|
||
executor.submit { | ||
Sentry.setCurrentHub(threadedHub) | ||
}.get() | ||
|
||
assertEquals(mainHub, Sentry.getCurrentHub()) | ||
|
||
val callableFuture = | ||
executor.submit( | ||
sut.decorate { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertNotEquals(threadedHub, Sentry.getCurrentHub()) | ||
} | ||
) | ||
|
||
callableFuture.get() | ||
|
||
executor.submit { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertEquals(threadedHub, Sentry.getCurrentHub()) | ||
}.get() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.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,60 @@ | ||
package io.sentry.spring.webflux | ||
|
||
import io.sentry.Sentry | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class SentryScheduleHookTest { | ||
|
||
private val dsn = "http://key@localhost/proj" | ||
private lateinit var executor: ExecutorService | ||
|
||
@BeforeTest | ||
fun beforeTest() { | ||
executor = Executors.newSingleThreadExecutor() | ||
} | ||
|
||
@AfterTest | ||
fun afterTest() { | ||
Sentry.close() | ||
executor.shutdown() | ||
} | ||
|
||
@Test | ||
fun `hub is reset to its state within the thread after hook is done`() { | ||
Sentry.init { | ||
it.dsn = dsn | ||
} | ||
|
||
val sut = SentryScheduleHook() | ||
|
||
val mainHub = Sentry.getCurrentHub() | ||
val threadedHub = Sentry.getCurrentHub().clone() | ||
|
||
executor.submit { | ||
Sentry.setCurrentHub(threadedHub) | ||
}.get() | ||
|
||
assertEquals(mainHub, Sentry.getCurrentHub()) | ||
|
||
val callableFuture = | ||
executor.submit( | ||
sut.apply { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertNotEquals(threadedHub, Sentry.getCurrentHub()) | ||
} | ||
) | ||
|
||
callableFuture.get() | ||
|
||
executor.submit { | ||
assertNotEquals(mainHub, Sentry.getCurrentHub()) | ||
assertEquals(threadedHub, Sentry.getCurrentHub()) | ||
}.get() | ||
} | ||
} |
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
Oops, something went wrong.