File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
core/kotlinx-coroutines-test/src Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ interface ExceptionCaptor {
16
16
*
17
17
* During [cleanupTestCoroutines] the first element of this list will be rethrown if it is not empty.
18
18
*/
19
- val exceptions: MutableList <Throwable >
19
+ val exceptions: List <Throwable >
20
20
21
21
/* *
22
22
* Call after the test completes.
@@ -30,16 +30,25 @@ interface ExceptionCaptor {
30
30
* An exception handler that can be used to capture uncaught exceptions in tests.
31
31
*/
32
32
class TestCoroutineExceptionHandler : ExceptionCaptor , CoroutineExceptionHandler {
33
+ val lock = Object ()
34
+
33
35
override fun handleException (context : CoroutineContext , exception : Throwable ) {
34
- exceptions + = exception
36
+ synchronized(lock) {
37
+ _exceptions + = exception
38
+ }
35
39
}
36
40
37
41
override val key = CoroutineExceptionHandler
38
42
39
- override val exceptions = LinkedList <Throwable >()
43
+ private val _exceptions = mutableListOf<Throwable >()
44
+
45
+ override val exceptions
46
+ get() = _exceptions .toList()
40
47
41
48
override fun cleanupTestCoroutines () {
42
- val exception = exceptions.firstOrNull() ? : return
43
- throw exception
49
+ synchronized(lock) {
50
+ val exception = _exceptions .firstOrNull() ? : return
51
+ throw exception
52
+ }
44
53
}
45
54
}
You can’t perform that action at this time.
0 commit comments