Skip to content

Commit

Permalink
Update lincheck tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Apr 13, 2021
1 parent de18150 commit 3ba936b
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ abstract class ChannelLincheckTestBase(
fun trySend(@Param(name = "value") value: Int): Any = c.trySend(value)
.onSuccess { return true }
.onFailure {
if (it is NumberedCancellationException) return it.testResult
else throw it!!
return if (it is NumberedCancellationException) it.testResult
else false
}

// TODO: this operation should be (and can be!) linearizable, but is not
Expand All @@ -85,11 +85,11 @@ abstract class ChannelLincheckTestBase(
e.testResult
}

@Operation
// @Operation TODO Lincheck doesn't work with inline classes
fun tryReceive(): Any? =
c.tryReceive()
.onSuccess { it }
.onFailure { if (it is NumberedCancellationException) it.testResult else throw it!! }
.onSuccess { return it }
.onFailure { return if (it is NumberedCancellationException) it.testResult else null }

// TODO: this operation should be (and can be!) linearizable, but is not
// @Operation
Expand Down Expand Up @@ -131,15 +131,15 @@ abstract class SequentialIntChannelBase(private val capacity: Int) : VerifierSta
private val buffer = ArrayList<Int>()
private var closedMessage: String? = null

suspend fun send(x: Int): Any = when (val offerRes = offer(x)) {
suspend fun send(x: Int): Any = when (val offerRes = trySend(x)) {
true -> Unit
false -> suspendCancellableCoroutine { cont ->
senders.add(cont to x)
}
else -> offerRes
}

fun offer(element: Int): Any {
fun trySend(element: Int): Any {
if (closedMessage !== null) return closedMessage!!
if (capacity == CONFLATED) {
if (resumeFirstReceiver(element)) return true
Expand Down

0 comments on commit 3ba936b

Please sign in to comment.