@@ -16,96 +16,42 @@ class FlowableExceptionHandlingTest : TestBase() {
16
16
ignoreLostThreads(" RxComputationThreadPool-" , " RxCachedWorkerPoolEvictor-" , " RxSchedulerPurge-" )
17
17
}
18
18
19
- @Test
20
- fun testException () = runTest(expected = { it is TestException }) {
21
- rxFlowable<Int >(Dispatchers .Unconfined ) {
22
- expect(1 )
23
- throw TestException ()
24
- }.subscribe({
25
- expectUnreached()
26
- }, {
27
- expect(2 ) // Reported to onError
28
- })
29
- finish(3 )
19
+ private inline fun <reified T : Throwable > ceh (expect : Int ) = CoroutineExceptionHandler { _, t ->
20
+ assertTrue(t is T )
21
+ expect(expect)
30
22
}
31
23
32
- @Test
33
- fun testFatalException () = runTest(expected = { it is LinkageError }) {
34
- rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {
35
- expect(1 )
36
- throw LinkageError ()
37
- }.subscribe({
38
- expectUnreached()
39
- }, {
40
- expectUnreached() // Fatal exception is not reported in onError
41
- })
42
- finish(2 )
43
- }
24
+ private fun cehUnreached () = CoroutineExceptionHandler { _, _ -> expectUnreached() }
44
25
45
26
@Test
46
- fun testExceptionWithoutParent () = runTest {
47
- GlobalScope . rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, _ -> expectUnreached() } ) {
27
+ fun testException () = runTest {
28
+ rxFlowable<Int >(Dispatchers .Unconfined + cehUnreached() ) {
48
29
expect(1 )
49
30
throw TestException ()
50
31
}.subscribe({
51
32
expectUnreached()
52
33
}, {
53
- assertTrue(it is TestException )
54
34
expect(2 ) // Reported to onError
55
35
})
56
36
finish(3 )
57
37
}
58
38
59
39
@Test
60
- fun testFatalExceptionWithoutParent () = runTest {
61
- GlobalScope .rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, e ->
62
- assertTrue(e is LinkageError ); expect(
63
- 2
64
- )
65
- }) {
40
+ fun testFatalException () = runTest {
41
+ rxFlowable<Int >(Dispatchers .Unconfined + ceh<LinkageError >(3 )) {
66
42
expect(1 )
67
43
throw LinkageError ()
68
44
}.subscribe({
69
45
expectUnreached()
70
46
}, {
71
- expectUnreached( ) // Fatal exception is not reported in onError
47
+ expect( 2 ) // Fatal exception is reported to both onError and CEH
72
48
})
73
- finish(3 )
74
- }
75
-
76
- @Test
77
- fun testExceptionAsynchronous () = runTest(expected = { it is TestException }) {
78
- rxFlowable<Int >(Dispatchers .Unconfined ) {
79
- expect(1 )
80
- throw TestException ()
81
- }.publish()
82
- .refCount()
83
- .subscribe({
84
- expectUnreached()
85
- }, {
86
- expect(2 ) // Reported to onError
87
- })
88
- finish(3 )
89
- }
90
-
91
- @Test
92
- fun testFatalExceptionAsynchronous () = runTest(expected = { it is LinkageError }) {
93
- rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {
94
- expect(1 )
95
- throw LinkageError ()
96
- }.publish()
97
- .refCount()
98
- .subscribe({
99
- expectUnreached()
100
- }, {
101
- expectUnreached() // Fatal exception is not reported in onError
102
- })
103
- finish(2 )
49
+ finish(4 )
104
50
}
105
51
106
52
@Test
107
- fun testExceptionAsynchronousWithoutParent () = runTest {
108
- GlobalScope . rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, _ -> expectUnreached() } ) {
53
+ fun testExceptionAsynchronous () = runTest {
54
+ rxFlowable<Int >(Dispatchers .Unconfined + cehUnreached() ) {
109
55
expect(1 )
110
56
throw TestException ()
111
57
}.publish()
@@ -119,37 +65,35 @@ class FlowableExceptionHandlingTest : TestBase() {
119
65
}
120
66
121
67
@Test
122
- fun testFatalExceptionAsynchronousWithoutParent () = runTest {
123
- GlobalScope .rxFlowable<Int >(Dispatchers .Unconfined + CoroutineExceptionHandler { _, e ->
124
- assertTrue(e is LinkageError ); expect(2 )
125
- }) {
68
+ fun testFatalExceptionAsynchronous () = runTest {
69
+ rxFlowable<Int >(Dispatchers .Unconfined + ceh<LinkageError >(3 )) {
126
70
expect(1 )
127
71
throw LinkageError ()
128
72
}.publish()
129
73
.refCount()
130
74
.subscribe({
131
75
expectUnreached()
132
76
}, {
133
- expectUnreached() // Fatal exception is not reported in onError
77
+ expect( 2 )
134
78
})
135
- finish(3 )
79
+ finish(4 )
136
80
}
137
81
138
82
@Test
139
- fun testFatalExceptionFromSubscribe () = runTest(expected = { it is LinkageError }) {
140
- rxFlowable(Dispatchers .Unconfined ) {
83
+ fun testFatalExceptionFromSubscribe () = runTest {
84
+ rxFlowable(Dispatchers .Unconfined + ceh< LinkageError >( 4 ) ) {
141
85
expect(1 )
142
86
send(Unit )
143
87
}.subscribe({
144
88
expect(2 )
145
89
throw LinkageError ()
146
- }, { expectUnreached( ) }) // Unreached because fatal errors are rethrown
147
- finish(3 )
90
+ }, { expect( 3 ) }) // Fatal exception is reported to both onError and CEH
91
+ finish(5 )
148
92
}
149
93
150
94
@Test
151
95
fun testExceptionFromSubscribe () = runTest {
152
- rxFlowable(Dispatchers .Unconfined ) {
96
+ rxFlowable(Dispatchers .Unconfined + cehUnreached() ) {
153
97
expect(1 )
154
98
send(Unit )
155
99
}.subscribe({
@@ -161,7 +105,7 @@ class FlowableExceptionHandlingTest : TestBase() {
161
105
162
106
@Test
163
107
fun testAsynchronousExceptionFromSubscribe () = runTest {
164
- rxFlowable(Dispatchers .Unconfined ) {
108
+ rxFlowable(Dispatchers .Unconfined + cehUnreached() ) {
165
109
expect(1 )
166
110
send(Unit )
167
111
}.publish()
@@ -174,8 +118,8 @@ class FlowableExceptionHandlingTest : TestBase() {
174
118
}
175
119
176
120
@Test
177
- fun testAsynchronousFatalExceptionFromSubscribe () = runTest(expected = { it is LinkageError }) {
178
- rxFlowable(Dispatchers .Unconfined ) {
121
+ fun testAsynchronousFatalExceptionFromSubscribe () = runTest {
122
+ rxFlowable(Dispatchers .Unconfined + ceh< LinkageError >( 3 ) ) {
179
123
expect(1 )
180
124
send(Unit )
181
125
}.publish()
@@ -184,38 +128,6 @@ class FlowableExceptionHandlingTest : TestBase() {
184
128
expect(2 )
185
129
throw LinkageError ()
186
130
}, { expectUnreached() })
187
- finish(3 )
131
+ finish(4 )
188
132
}
189
-
190
- @Test
191
- fun testAsynchronousExceptionFromSubscribeWithoutParent () =
192
- runTest {
193
- GlobalScope .rxFlowable(Dispatchers .Unconfined ) {
194
- expect(1 )
195
- send(Unit )
196
- }.publish()
197
- .refCount()
198
- .subscribe({
199
- expect(2 )
200
- throw RuntimeException ()
201
- }, { expect(3 ) })
202
- finish(4 )
203
- }
204
-
205
- @Test
206
- fun testAsynchronousFatalExceptionFromSubscribeWithoutParent () =
207
- runTest {
208
- GlobalScope .rxFlowable(Dispatchers .Unconfined + CoroutineExceptionHandler { _, e ->
209
- assertTrue(e is LinkageError ); expect(3 )
210
- }) {
211
- expect(1 )
212
- send(Unit )
213
- }.publish()
214
- .refCount()
215
- .subscribe({
216
- expect(2 )
217
- throw LinkageError ()
218
- }, { expectUnreached() })
219
- finish(4 )
220
- }
221
133
}
0 commit comments