Skip to content

Commit df3aae1

Browse files
Nikita Kovalqwwdfsad
Nikita Koval
authored andcommitted
Fix the ChannelUndeliveredElementSelectOldStressTest
1 parent 7877e21 commit df3aae1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Diff for: kotlinx-coroutines-core/jvm/test/channels/ChannelUndeliveredElementSelectOldStressTest.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
201201

202202
private suspend fun stopReceiver() {
203203
stoppedReceiver++
204-
receiver.cancel()
204+
receiver.cancelAndJoin()
205205
receiverDone.receive()
206206
}
207207

208208
private inner class Data(val x: Long) {
209209
private val firstFailedToDeliverOrReceivedCallTrace = atomic<Exception?>(null)
210210

211211
fun failedToDeliver() {
212-
val trace = Exception("First onUndeliveredElement() call")
212+
val trace = if (TRACING_ENABLED) Exception("First onUndeliveredElement() call") else DUMMY_TRACE_EXCEPTION
213213
if (firstFailedToDeliverOrReceivedCallTrace.compareAndSet(null, trace)) {
214214
failedToDeliverCnt.incrementAndGet()
215215
failedStatus[x] = 1
@@ -219,7 +219,7 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
219219
}
220220

221221
fun onReceived() {
222-
val trace = Exception("First onReceived() call")
222+
val trace = if (TRACING_ENABLED) Exception("First onReceived() call") else DUMMY_TRACE_EXCEPTION
223223
if (firstFailedToDeliverOrReceivedCallTrace.compareAndSet(null, trace)) return
224224
throw IllegalStateException("onUndeliveredElement()/onReceived() notified twice", firstFailedToDeliverOrReceivedCallTrace.value!!)
225225
}
@@ -249,3 +249,6 @@ class ChannelUndeliveredElementSelectOldStressTest(private val kind: TestChannel
249249
}
250250
}
251251
}
252+
253+
private const val TRACING_ENABLED = false // Change to `true` to enable the tracing
254+
private val DUMMY_TRACE_EXCEPTION = Exception("The tracing is disabled; please enable it by changing the `TRACING_ENABLED` constant to `true`.")

Diff for: kotlinx-coroutines-core/jvm/test/channels/ChannelUndeliveredElementStressTest.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class ChannelUndeliveredElementStressTest(private val kind: TestChannelKind) : T
176176

177177
private suspend fun stopSender() {
178178
stoppedSender++
179-
sender.cancel()
179+
sender.cancelAndJoin()
180180
senderDone.receive()
181181
}
182182

@@ -224,7 +224,7 @@ class ChannelUndeliveredElementStressTest(private val kind: TestChannelKind) : T
224224
private val firstFailedToDeliverOrReceivedCallTrace = atomic<Exception?>(null)
225225

226226
fun failedToDeliver() {
227-
val trace = if (TRACING_ENABLED) Exception("First onUndeliveredElement() call") else DUMMY_TRACING_EXCEPTION
227+
val trace = if (TRACING_ENABLED) Exception("First onUndeliveredElement() call") else DUMMY_TRACE_EXCEPTION
228228
if (firstFailedToDeliverOrReceivedCallTrace.compareAndSet(null, trace)) {
229229
failedToDeliverCnt.incrementAndGet()
230230
failedStatus[x] = 1
@@ -234,7 +234,7 @@ class ChannelUndeliveredElementStressTest(private val kind: TestChannelKind) : T
234234
}
235235

236236
fun onReceived() {
237-
val trace = if (TRACING_ENABLED) Exception("First onReceived() call") else DUMMY_TRACING_EXCEPTION
237+
val trace = if (TRACING_ENABLED) Exception("First onReceived() call") else DUMMY_TRACE_EXCEPTION
238238
if (firstFailedToDeliverOrReceivedCallTrace.compareAndSet(null, trace)) return
239239
throw IllegalStateException("onUndeliveredElement()/onReceived() notified twice", firstFailedToDeliverOrReceivedCallTrace.value!!)
240240
}
@@ -265,5 +265,5 @@ class ChannelUndeliveredElementStressTest(private val kind: TestChannelKind) : T
265265
}
266266
}
267267

268-
private const val TRACING_ENABLED = false // Change to `true` to enable tracing while
269-
private val DUMMY_TRACING_EXCEPTION = Exception("The tracing is disabled; please enable it by changing the `TRACING_ENABLED` constant to `true`.")
268+
private const val TRACING_ENABLED = false // Change to `true` to enable the tracing
269+
private val DUMMY_TRACE_EXCEPTION = Exception("The tracing is disabled; please enable it by changing the `TRACING_ENABLED` constant to `true`.")

0 commit comments

Comments
 (0)