@@ -42,9 +42,9 @@ import org.mockito.kotlin.verify
4242import org.mockito.kotlin.whenever
4343import org.springframework.beans.factory.annotation.Autowired
4444import org.springframework.boot.autoconfigure.SpringBootApplication
45+ import org.springframework.boot.resttestclient.TestRestTemplate
4546import org.springframework.boot.test.context.SpringBootTest
46- import org.springframework.boot.web.server.test.LocalServerPort
47- import org.springframework.boot.web.server.test.client.TestRestTemplate
47+ import org.springframework.boot.test.web.server.LocalServerPort
4848import org.springframework.boot.web.servlet.FilterRegistrationBean
4949import org.springframework.context.annotation.Bean
5050import org.springframework.context.annotation.Configuration
@@ -80,13 +80,15 @@ import org.springframework.web.reactive.function.client.WebClient
8080class SentrySpringIntegrationTest {
8181
8282 companion object {
83+ @JvmStatic
8384 @BeforeClass
84- fun `configure awaitlity` () {
85+ fun `configure awaitlity` (): Unit {
8586 Awaitility .setDefaultTimeout(500 , TimeUnit .MILLISECONDS )
8687 }
8788
89+ @JvmStatic
8890 @AfterClass
89- fun `reset awaitility` () {
91+ fun `reset awaitility` (): Unit {
9092 Awaitility .reset()
9193 }
9294 }
@@ -115,17 +117,19 @@ class SentrySpringIntegrationTest {
115117
116118 restTemplate.exchange(" http://localhost:$port /hello" , HttpMethod .GET , entity, Void ::class .java)
117119
118- verify(transport)
119- .send(
120- checkEvent { event ->
121- assertThat(event.request).isNotNull()
122- assertThat(event.request!! .url).isEqualTo(" http://localhost:$port /hello" )
123- assertThat(event.user).isNotNull()
124- assertThat(event.user!! .username).isEqualTo(" user" )
125- assertThat(event.user!! .ipAddress).isEqualTo(" 169.128.0.1" )
126- },
127- anyOrNull(),
128- )
120+ await.untilAsserted {
121+ verify(transport)
122+ .send(
123+ checkEvent { event ->
124+ assertThat(event.request).isNotNull()
125+ assertThat(event.request!! .url).isEqualTo(" http://localhost:$port /hello" )
126+ assertThat(event.user).isNotNull()
127+ assertThat(event.user!! .username).isEqualTo(" user" )
128+ assertThat(event.user!! .ipAddress).isEqualTo(" 169.128.0.1" )
129+ },
130+ anyOrNull(),
131+ )
132+ }
129133 }
130134
131135 @Test
@@ -140,14 +144,16 @@ class SentrySpringIntegrationTest {
140144 Void ::class .java,
141145 )
142146
143- verify(transport)
144- .send(
145- checkEvent { event ->
146- assertThat(event.request).isNotNull()
147- assertThat(event.request!! .data).isEqualTo(""" {"body":"content"}""" )
148- },
149- anyOrNull(),
150- )
147+ await.untilAsserted {
148+ verify(transport)
149+ .send(
150+ checkEvent { event ->
151+ assertThat(event.request).isNotNull()
152+ assertThat(event.request!! .data).isEqualTo(""" {"body":"content"}""" )
153+ },
154+ anyOrNull(),
155+ )
156+ }
151157 }
152158
153159 @Test
@@ -162,14 +168,16 @@ class SentrySpringIntegrationTest {
162168 Void ::class .java,
163169 )
164170
165- verify(transport)
166- .send(
167- checkEvent { event ->
168- assertThat(event.request).isNotNull()
169- assertThat(event.request!! .data).isEqualTo(""" {"body":"content"}""" )
170- },
171- anyOrNull(),
172- )
171+ await.untilAsserted {
172+ verify(transport)
173+ .send(
174+ checkEvent { event ->
175+ assertThat(event.request).isNotNull()
176+ assertThat(event.request!! .data).isEqualTo(""" {"body":"content"}""" )
177+ },
178+ anyOrNull(),
179+ )
180+ }
173181 }
174182
175183 @Test
@@ -181,14 +189,16 @@ class SentrySpringIntegrationTest {
181189
182190 restTemplate.exchange(" http://localhost:$port /hello" , HttpMethod .GET , entity, Void ::class .java)
183191
184- verify(transport)
185- .send(
186- checkEvent { event ->
187- assertThat(event.user).isNotNull()
188- assertThat(event.user!! .ipAddress).isEqualTo(" 169.128.0.1" )
189- },
190- anyOrNull(),
191- )
192+ await.untilAsserted {
193+ verify(transport)
194+ .send(
195+ checkEvent { event ->
196+ assertThat(event.user).isNotNull()
197+ assertThat(event.user!! .ipAddress).isEqualTo(" 169.128.0.1" )
198+ },
199+ anyOrNull(),
200+ )
201+ }
192202 }
193203
194204 @Test
@@ -197,18 +207,20 @@ class SentrySpringIntegrationTest {
197207
198208 restTemplate.getForEntity(" http://localhost:$port /throws" , String ::class .java)
199209
200- verify(transport)
201- .send(
202- checkEvent { event ->
203- assertThat(event.exceptions).isNotNull().isNotEmpty
204- val ex = event.exceptions!! .first()
205- assertThat(ex.value).isEqualTo(" something went wrong" )
206- assertThat(ex.mechanism).isNotNull()
207- assertThat(ex.mechanism!! .isHandled).isFalse()
208- assertThat(ex.mechanism!! .type).isEqualTo(SentryExceptionResolver .MECHANISM_TYPE )
209- },
210- anyOrNull(),
211- )
210+ await.untilAsserted {
211+ verify(transport)
212+ .send(
213+ checkEvent { event ->
214+ assertThat(event.exceptions).isNotNull().isNotEmpty
215+ val ex = event.exceptions!! .first()
216+ assertThat(ex.value).isEqualTo(" something went wrong" )
217+ assertThat(ex.mechanism).isNotNull()
218+ assertThat(ex.mechanism!! .isHandled).isFalse()
219+ assertThat(ex.mechanism!! .type).isEqualTo(SentryExceptionResolver .MECHANISM_TYPE )
220+ },
221+ anyOrNull(),
222+ )
223+ }
212224 }
213225
214226 @Test
@@ -217,11 +229,13 @@ class SentrySpringIntegrationTest {
217229
218230 restTemplate.getForEntity(" http://localhost:$port /throws" , String ::class .java)
219231
220- verify(transport)
221- .send(
222- checkEvent { event -> assertThat(event.transaction).isEqualTo(" GET /throws" ) },
223- anyOrNull(),
224- )
232+ await.untilAsserted {
233+ verify(transport)
234+ .send(
235+ checkEvent { event -> assertThat(event.transaction).isEqualTo(" GET /throws" ) },
236+ anyOrNull(),
237+ )
238+ }
225239 }
226240
227241 @Test
@@ -230,7 +244,7 @@ class SentrySpringIntegrationTest {
230244
231245 restTemplate.getForEntity(" http://localhost:$port /throws-handled" , String ::class .java)
232246
233- await.during(Duration .ofSeconds(2 )).untilAsserted {
247+ await.atMost( 3 , TimeUnit . SECONDS ). during(Duration .ofSeconds(2 )).untilAsserted {
234248 verify(transport, never())
235249 .send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
236250 }
@@ -240,29 +254,35 @@ class SentrySpringIntegrationTest {
240254 fun `calling a method annotated with @SentryCaptureException captures exception` () {
241255 val exception = java.lang.RuntimeException (" test exception" )
242256 anotherService.aMethodThatTakesAnException(exception)
243- verify(transport)
244- .send(
245- checkEvent { assertThat(it.exceptions!! .first().value).isEqualTo(exception.message) },
246- anyOrNull(),
247- )
257+ await.untilAsserted {
258+ verify(transport)
259+ .send(
260+ checkEvent { assertThat(it.exceptions!! .first().value).isEqualTo(exception.message) },
261+ anyOrNull(),
262+ )
263+ }
248264 }
249265
250266 @Test
251267 fun `calling a method annotated with @SentryCaptureException captures exception in later param` () {
252268 val exception = java.lang.RuntimeException (" test exception" )
253269 anotherService.aMethodThatTakesAnExceptionAsLaterParam(" a" , " b" , exception)
254- verify(transport)
255- .send(
256- checkEvent { assertThat(it.exceptions!! .first().value).isEqualTo(exception.message) },
257- anyOrNull(),
258- )
270+ await.untilAsserted {
271+ verify(transport)
272+ .send(
273+ checkEvent { assertThat(it.exceptions!! .first().value).isEqualTo(exception.message) },
274+ anyOrNull(),
275+ )
276+ }
259277 }
260278
261279 @Test
262280 fun `calling a method annotated with @SentryTransaction creates transaction` () {
263281 someService.aMethod()
264- verify(transport)
265- .send(checkTransaction { assertThat(it.status).isEqualTo(SpanStatus .OK ) }, anyOrNull())
282+ await.untilAsserted {
283+ verify(transport)
284+ .send(checkTransaction { assertThat(it.status).isEqualTo(SpanStatus .OK ) }, anyOrNull())
285+ }
266286 }
267287
268288 @Test
@@ -272,14 +292,16 @@ class SentrySpringIntegrationTest {
272292 } catch (e: Exception ) {
273293 scopes.captureException(e)
274294 }
275- verify(transport)
276- .send(
277- checkEvent {
278- assertThat(it.contexts.trace).isNotNull
279- assertThat(it.contexts.trace!! .operation).isEqualTo(" bean" )
280- },
281- anyOrNull(),
282- )
295+ await.untilAsserted {
296+ verify(transport)
297+ .send(
298+ checkEvent {
299+ assertThat(it.contexts.trace).isNotNull
300+ assertThat(it.contexts.trace!! .operation).isEqualTo(" bean" )
301+ },
302+ anyOrNull(),
303+ )
304+ }
283305 }
284306
285307 @Test
@@ -289,14 +311,16 @@ class SentrySpringIntegrationTest {
289311 } catch (e: Exception ) {
290312 scopes.captureException(e)
291313 }
292- verify(transport)
293- .send(
294- checkEvent {
295- assertThat(it.contexts.trace).isNotNull
296- assertThat(it.contexts.trace!! .operation).isEqualTo(" child-op" )
297- },
298- anyOrNull(),
299- )
314+ await.untilAsserted {
315+ verify(transport)
316+ .send(
317+ checkEvent {
318+ assertThat(it.contexts.trace).isNotNull
319+ assertThat(it.contexts.trace!! .operation).isEqualTo(" child-op" )
320+ },
321+ anyOrNull(),
322+ )
323+ }
300324 }
301325
302326 @Test
0 commit comments