@@ -127,25 +127,33 @@ class CancellationTest {
127
127
service.cancellationInOutgoingStream(
128
128
stream = flow {
129
129
emit(42 )
130
+ println (" [testCancellationInClientStream] emit 42" )
130
131
emit(43 )
132
+ println (" [testCancellationInClientStream] emit 43" )
131
133
},
132
134
cancelled = flow {
133
135
emit(1 )
136
+ println (" [testCancellationInClientStream] emit 1" )
134
137
serverInstance().firstIncomingConsumed.await()
138
+ println (" [testCancellationInClientStream] firstIncomingConsumed" )
135
139
throw CancellationException (" cancellationInClientStream" )
136
140
},
137
141
)
138
142
}
139
143
140
144
requestJob.join()
145
+ println (" [testCancellationInClientStream] Request job finished" )
141
146
serverInstance().consumedAll.await()
147
+ println (" [testCancellationInClientStream] Server consumed all" )
142
148
143
149
assertFalse(requestJob.isCancelled, " Expected requestJob not to be cancelled" )
144
150
assertContentEquals(listOf (42 , 43 ), serverInstance().consumedIncomingValues)
145
151
}
152
+ println (" [testCancellationInClientStream] Scope finished" )
146
153
147
154
checkAlive()
148
155
stopAllAndJoin()
156
+ println (" [testCancellationInClientStream] All done" )
149
157
150
158
assertEquals(1 , serverInstance().cancellationsCounter.value, " Expected 1 request to be cancelled" )
151
159
}
@@ -154,19 +162,23 @@ class CancellationTest {
154
162
@Test
155
163
fun testCancelClient () = runCancellationTest {
156
164
val firstRequestJob = launch {
165
+ println (" [testCancelClient] firstRequestJob started" )
157
166
service.longRequest()
158
167
}
159
168
160
169
val secondService = client.withService<CancellationService >()
161
170
162
171
val secondRequestJob = launch {
172
+ println (" [testCancelClient] secondRequestJob started" )
163
173
secondService.longRequest()
164
174
}
165
175
166
176
val clientFlowJob = launch {
167
177
service.outgoingStream(flow {
168
178
emit(0 )
179
+ println (" [testCancelClient] emit 0" )
169
180
serverInstance().fence.await()
181
+ println (" [testCancelClient] fence awaited" )
170
182
emit(1 )
171
183
})
172
184
}
@@ -181,18 +193,27 @@ class CancellationTest {
181
193
}
182
194
}
183
195
196
+ println (" [testCancelClient] Requests sent" )
184
197
serverInstance().waitCounter.await(4 )
198
+ println (" [testCancelClient] Requests reached" )
185
199
client.close()
186
200
client.awaitCompletion()
201
+ println (" [testCancelClient] Client stopped" )
187
202
server.awaitCompletion()
203
+ println (" [testCancelClient] Server stopped" )
188
204
firstRequestJob.join()
205
+ println (" [testCancelClient] First request finished" )
189
206
secondRequestJob.join()
207
+ println (" [testCancelClient] Second request finished" )
190
208
clientFlowJob.join()
209
+ println (" [testCancelClient] Client flow finished" )
191
210
192
211
serverInstance().fence.complete(Unit )
193
212
serverFlowJob.join()
213
+ println (" [testCancelClient] Server flow finished" )
194
214
195
215
serverInstance().cancellationsCounter.await(4 )
216
+ println (" [testCancelClient] Server cancellations counted" )
196
217
197
218
assertTrue(firstRequestJob.isCancelled, " Expected firstRequestJob to be cancelled" )
198
219
assertTrue(secondRequestJob.isCancelled, " Expected secondRequestJob to be cancelled" )
@@ -203,26 +224,31 @@ class CancellationTest {
203
224
204
225
checkAlive(clientAlive = false , serverAlive = false )
205
226
stopAllAndJoin()
227
+ println (" [testCancelClient] All done" )
206
228
207
229
assertEquals(4 , serverInstance().cancellationsCounter.value, " Expected 4 requests to be cancelled" )
208
230
}
209
231
210
232
@Test
211
233
fun testCancelServer () = runCancellationTest {
212
234
val firstRequestJob = launch {
235
+ println (" [testCancelServer] firstRequestJob started" )
213
236
service.longRequest()
214
237
}
215
238
216
239
val secondService = client.withService<CancellationService >()
217
240
218
241
val secondRequestJob = launch {
242
+ println (" [testCancelServer] secondRequestJob started" )
219
243
secondService.longRequest()
220
244
}
221
245
222
246
val clientFlowJob = launch {
223
247
service.outgoingStream(flow {
224
248
emit(0 )
249
+ println (" [testCancelServer] emit 0" )
225
250
serverInstance().fence.await()
251
+ println (" [testCancelServer] fence awaited" )
226
252
emit(1 )
227
253
})
228
254
}
@@ -237,18 +263,27 @@ class CancellationTest {
237
263
}
238
264
}
239
265
266
+ println (" [testCancelServer] Requests sent" )
240
267
serverInstance().waitCounter.await(4 ) // wait for requests to reach server
268
+ println (" [testCancelServer] Requests reached" )
241
269
server.close()
242
270
server.awaitCompletion()
271
+ println (" [testCancelServer] Server stopped" )
243
272
client.awaitCompletion()
273
+ println (" [testCancelServer] Client stopped" )
244
274
firstRequestJob.join()
275
+ println (" [testCancelServer] First request finished" )
245
276
secondRequestJob.join()
277
+ println (" [testCancelServer] Second request finished" )
246
278
clientFlowJob.join()
279
+ println (" [testCancelServer] Client flow finished" )
247
280
248
281
serverInstance().fence.complete(Unit )
249
282
serverFlowJob.join()
283
+ println (" [testCancelServer] Server flow finished" )
250
284
251
285
serverInstance().cancellationsCounter.await(4 )
286
+ println (" [testCancelServer] Server cancellations counted" )
252
287
253
288
assertTrue(firstRequestJob.isCancelled, " Expected firstRequestJob to be cancelled" )
254
289
assertTrue(secondRequestJob.isCancelled, " Expected secondRequestJob to be cancelled" )
@@ -259,6 +294,7 @@ class CancellationTest {
259
294
260
295
checkAlive(clientAlive = false , serverAlive = false )
261
296
stopAllAndJoin()
297
+ println (" [testCancelServer] All done" )
262
298
263
299
assertEquals(4 , serverInstance().cancellationsCounter.value, " Expected 4 requests to be cancelled" )
264
300
}
0 commit comments