@@ -52,6 +52,8 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
52
52
53
53
private val modulo = 1 shl 25
54
54
private val mask = (modulo - 1 ).toLong()
55
+ private val sentStatus = ItemStatus () // 1 - send norm, 2 - send select, +2 - did not throw exception
56
+ private val receivedStatus = ItemStatus () // 1-6 received
55
57
private val failedStatus = ItemStatus () // 1 - failed
56
58
57
59
lateinit var sender: Job
@@ -111,8 +113,11 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
111
113
assertEquals(sentCnt - failedToDeliverCnt.value, receivedCnt)
112
114
} catch (e: Throwable ) {
113
115
printProgressSummary(iteration)
116
+ printErrorDetails()
114
117
throw e
115
118
}
119
+ sentStatus.clear()
120
+ receivedStatus.clear()
116
121
failedStatus.clear()
117
122
}
118
123
@@ -126,15 +131,34 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
126
131
println (" Duplicated $dupCnt deliveries" )
127
132
}
128
133
134
+ private fun printErrorDetails () {
135
+ val min = minOf(sentStatus.min, receivedStatus.min, failedStatus.min)
136
+ val max = maxOf(sentStatus.max, receivedStatus.max, failedStatus.max)
137
+ for (x in min.. max) {
138
+ val sentCnt = if (sentStatus[x] != 0 ) 1 else 0
139
+ val receivedCnt = if (receivedStatus[x] != 0 ) 1 else 0
140
+ val failedToDeliverCnt = failedStatus[x]
141
+ if (sentCnt - failedToDeliverCnt != receivedCnt) {
142
+ println (" !!! Error for value $x : " +
143
+ " sentStatus=${sentStatus[x]} , " +
144
+ " receivedStatus=${receivedStatus[x]} , " +
145
+ " failedStatus=${failedStatus[x]} "
146
+ )
147
+ }
148
+ }
149
+ }
150
+
151
+
129
152
private fun launchSender () {
130
153
sender = scope.launch(start = CoroutineStart .ATOMIC ) {
131
154
cancellable(senderDone) {
132
155
var counter = 0
133
156
while (true ) {
134
157
val trySendData = Data (sentCnt++ )
135
- selectOld<Unit > {
136
- channel.onSend(trySendData) {}
137
- }
158
+ val sendMode = Random .nextInt(2 ) + 1
159
+ sentStatus[trySendData.x] = sendMode
160
+ selectOld<Unit > { channel.onSend(trySendData) {} }
161
+ sentStatus[trySendData.x] = sendMode + 2
138
162
when {
139
163
// must artificially slow down LINKED_LIST sender to avoid overwhelming receiver and going OOM
140
164
kind == TestChannelKind .LINKED_LIST -> while (sentCnt > lastReceived + 100 ) yield ()
@@ -156,14 +180,15 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
156
180
receiver = scope.launch(start = CoroutineStart .ATOMIC ) {
157
181
cancellable(receiverDone) {
158
182
while (true ) {
159
- selectOld<Unit > {
160
- channel.onReceive {
161
- it .onReceived()
183
+ selectOld<Unit > {
184
+ channel.onReceive { receivedData ->
185
+ receivedData .onReceived()
162
186
receivedCnt++
163
- val received = it .x
187
+ val received = receivedData .x
164
188
if (received <= lastReceived)
165
189
dupCnt++
166
190
lastReceived = received
191
+ receivedStatus[received] = 1
167
192
}
168
193
}
169
194
}
0 commit comments