@@ -17,10 +17,10 @@ public void Start()
1717 switch ( arg )
1818 {
1919 case "message-capture" :
20- MessageCapture ( ) ;
20+ StartCoroutine ( MessageCapture ( ) ) ;
2121 break ;
2222 case "exception-capture" :
23- ExceptionCapture ( ) ;
23+ StartCoroutine ( ExceptionCapture ( ) ) ;
2424 break ;
2525 case "crash-capture" :
2626 StartCoroutine ( CrashCapture ( ) ) ;
@@ -56,21 +56,17 @@ private void AddIntegrationTestContext(string testType)
5656 SentrySdk . AddBreadcrumb ( "Context configuration finished" ) ;
5757 }
5858
59- private void MessageCapture ( )
59+ private IEnumerator MessageCapture ( )
6060 {
6161 AddIntegrationTestContext ( "message-capture" ) ;
6262
6363 var eventId = SentrySdk . CaptureMessage ( "Integration test message" ) ;
6464 Debug . Log ( $ "EVENT_CAPTURED: { eventId } ") ;
6565
66- SentrySdk . FlushAsync ( TimeSpan . FromSeconds ( 5 ) ) . GetAwaiter ( ) . GetResult ( ) ;
67- Debug . Log ( "INTEGRATION_TEST_COMPLETE" ) ;
68- #if ! UNITY_WEBGL
69- Application . Quit ( 0 ) ;
70- #endif
66+ yield return CompleteAndQuit ( ) ;
7167 }
7268
73- private void ExceptionCapture ( )
69+ private IEnumerator ExceptionCapture ( )
7470 {
7571 AddIntegrationTestContext ( "exception-capture" ) ;
7672
@@ -84,10 +80,21 @@ private void ExceptionCapture()
8480 Debug . Log ( $ "EVENT_CAPTURED: { eventId } ") ;
8581 }
8682
87- SentrySdk . FlushAsync ( TimeSpan . FromSeconds ( 5 ) ) . GetAwaiter ( ) . GetResult ( ) ;
83+ yield return CompleteAndQuit ( ) ;
84+ }
85+
86+ private IEnumerator CompleteAndQuit ( )
87+ {
88+ #if UNITY_WEBGL
89+ // On WebGL, envelope sends are coroutine-based and need additional frames to
90+ // complete. Wait to avoid a race where the test harness shuts down the browser
91+ // before the send finishes.
92+ yield return new WaitForSeconds ( 3 ) ;
93+ Debug . Log ( "INTEGRATION_TEST_COMPLETE" ) ;
94+ #else
8895 Debug . Log ( "INTEGRATION_TEST_COMPLETE" ) ;
89- #if ! UNITY_WEBGL
9096 Application . Quit ( 0 ) ;
97+ yield break ;
9198#endif
9299 }
93100
0 commit comments