@@ -24,12 +24,10 @@ import kotlinx.coroutines.channels.Channel
24
24
import kotlinx.coroutines.channels.consume
25
25
import kotlinx.coroutines.channels.produce
26
26
import kotlinx.coroutines.isActive
27
- import kotlinx.coroutines.runBlocking
28
27
import kotlinx.coroutines.suspendCancellableCoroutine
29
28
import kotlin.test.BeforeTest
30
29
import kotlin.test.Test
31
30
import kotlin.test.assertEquals
32
- import kotlin.test.assertFails
33
31
import kotlin.test.assertFailsWith
34
32
import kotlin.test.assertFalse
35
33
import kotlin.test.assertNull
@@ -83,7 +81,9 @@ class WorkflowOperatorsTest {
83
81
it.toString()
84
82
}
85
83
86
- withAdaptedEvents.cancel(CancellationException (null , ExpectedException ()))
84
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
85
+ @Suppress(" DEPRECATION" )
86
+ withAdaptedEvents.cancel(ExpectedException ())
87
87
88
88
assertTrue(sourceCancellation is CancellationException )
89
89
}
@@ -161,7 +161,9 @@ class WorkflowOperatorsTest {
161
161
val withMappedStates = source.mapState { it }
162
162
163
163
assertNull(sourceCancellation)
164
- withMappedStates.cancel(CancellationException (null , ExpectedException ()))
164
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
165
+ @Suppress(" DEPRECATION" )
166
+ withMappedStates.cancel(ExpectedException ())
165
167
assertTrue(sourceCancellation is CancellationException )
166
168
}
167
169
@@ -306,16 +308,7 @@ class WorkflowOperatorsTest {
306
308
.consume {
307
309
assertFalse(withMappedStates.isCompleted)
308
310
withMappedStates.sendEvent(Unit )
309
- assertFails { runBlocking { receive() } }
310
- .also { error ->
311
- // Search up the cause chain for the expected exception, since multiple CancellationExceptions
312
- // may be chained together first.
313
- val causeChain = generateSequence(error) { it.cause }
314
- assertEquals(
315
- 1 , causeChain.count { it is ExpectedException },
316
- " Expected cancellation exception cause chain to include ExpectedException."
317
- )
318
- }
311
+ assertFailsWith<ExpectedException > { poll() }
319
312
// Exception is not sent through the result.
320
313
assertEquals(Unit , withMappedStates.getCompleted())
321
314
}
@@ -328,24 +321,17 @@ class WorkflowOperatorsTest {
328
321
}
329
322
val withMappedStates: Workflow <Int , Unit , Unit > = source.switchMapState {
330
323
Channel <Int >().apply {
331
- cancel(CancellationException (null , ExpectedException ()))
324
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
325
+ @Suppress(" DEPRECATION" )
326
+ cancel(ExpectedException ())
332
327
}
333
328
}
334
329
335
330
withMappedStates.openSubscriptionToState()
336
331
.consume {
337
332
assertFalse(withMappedStates.isCompleted)
338
333
withMappedStates.sendEvent(Unit )
339
- assertFails { runBlocking { receive() } }
340
- .also { error ->
341
- // Search up the cause chain for the expected exception, since multiple CancellationExceptions
342
- // may be chained together first.
343
- val causeChain = generateSequence(error) { it.cause }
344
- assertEquals(
345
- 1 , causeChain.count { it is ExpectedException },
346
- " Expected cancellation exception cause chain to include ExpectedException."
347
- )
348
- }
334
+ assertFailsWith<ExpectedException > { poll() }
349
335
// Exception is not sent through the result.
350
336
assertEquals(Unit , withMappedStates.getCompleted())
351
337
}
@@ -385,7 +371,9 @@ class WorkflowOperatorsTest {
385
371
withMappedStates.sendEvent(Unit )
386
372
387
373
assertFalse(transformedChannel.isClosedForSend)
388
- this .cancel(CancellationException (null , ExpectedException ()))
374
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
375
+ @Suppress(" DEPRECATION" )
376
+ this .cancel(ExpectedException ())
389
377
assertTrue(transformedChannel.isClosedForSend)
390
378
}
391
379
}
@@ -402,7 +390,9 @@ class WorkflowOperatorsTest {
402
390
val withMappedStates = source.switchMapState { produce { send(it) } }
403
391
404
392
assertNull(sourceCancellation)
405
- withMappedStates.cancel(CancellationException (null , ExpectedException ()))
393
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
394
+ @Suppress(" DEPRECATION" )
395
+ withMappedStates.cancel(ExpectedException ())
406
396
assertTrue(sourceCancellation is CancellationException )
407
397
}
408
398
@@ -460,7 +450,9 @@ class WorkflowOperatorsTest {
460
450
val withMappedResult = source.mapResult { it }
461
451
462
452
assertNull(sourceCancellation)
463
- withMappedResult.cancel(CancellationException (null , ExpectedException ()))
453
+ // TODO https://github.com/square/workflow/issues/188 Stop using parameterized cancel.
454
+ @Suppress(" DEPRECATION" )
455
+ withMappedResult.cancel(ExpectedException ())
464
456
assertTrue(sourceCancellation is CancellationException )
465
457
}
466
458
}
0 commit comments