@@ -50,9 +50,12 @@ class ChannelLFStressTest : TestBase() {
50
50
}
51
51
52
52
private fun performLockFreedomTest () {
53
- env.onCompletion { channel.close() }
54
- repeat(2 ) { env.testThread { sender() } }
55
- repeat(2 ) { env.testThread { receiver() } }
53
+ env.onCompletion {
54
+ // We must cancel the channel to abort both senders & receivers
55
+ channel.cancel(TestCompleted ())
56
+ }
57
+ repeat(2 ) { env.testThread(" sender-$it " ) { sender() } }
58
+ repeat(2 ) { env.testThread(" receiver-$it " ) { receiver() } }
56
59
env.performTest(nSeconds) {
57
60
println (" Sent: $sendIndex , Received: $receiveCount , dups: $duplicateCount " )
58
61
}
@@ -70,7 +73,7 @@ class ChannelLFStressTest : TestBase() {
70
73
val value = sendIndex.getAndIncrement()
71
74
try {
72
75
channel.send(value)
73
- } catch (e: ClosedSendChannelException ) {
76
+ } catch (e: TestCompleted ) {
74
77
check(env.isCompleted) // expected when test was completed
75
78
markReceived(value) // fake received (actually failed to send)
76
79
}
@@ -79,7 +82,7 @@ class ChannelLFStressTest : TestBase() {
79
82
private suspend fun receiver () {
80
83
val value = try {
81
84
channel.receive()
82
- } catch (e: ClosedReceiveChannelException ) {
85
+ } catch (e: TestCompleted ) {
83
86
check(env.isCompleted) // expected when test was completed
84
87
return
85
88
}
@@ -107,4 +110,6 @@ class ChannelLFStressTest : TestBase() {
107
110
val bits = receivedBits.get(index)
108
111
return bits and mask != 0L
109
112
}
113
+
114
+ private class TestCompleted : CancellationException ()
110
115
}
0 commit comments