JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
545 stars 31 forks source link

Track coroutine events in arbitrary code #260

Open eupp opened 5 months ago

eupp commented 5 months ago

Currently, the Lincheck supports only top-level suspend functions declared as operations.

That is, the following code is supported:


class RendezvousChannelTest {
    private val channel = Channel<Int>()

    @Operation
    suspend fun send(value: Int) = channel.send(value)

    ...

}

But the coroutines launched by the user code are not tracked and thus may work incorrectly. For example, the following code may not work as expected:


class LaunchTest {

    @Operation
    fun do(value: Int) {
       launch { ... }
    }

    ...

}

In order to support the latter case, the Lincheck need to be able to intercept coroutine's events (suspension, resumption, etc) in an arbitrary code.

Pros:

Cons:

ndkoval commented 5 months ago

@eupp, why would a data structure launch a coroutine?

eupp commented 5 months ago

why would a data structure launch a coroutine?

I mentioned that this is unlikely case:

Currently, the primary use case of Lincheck is to test concurrent data structures and synchronization primitives. This type of code rarely requires to create custom coroutines inside operations.

But I would rather prefer to keep this as a tracking issue, in case we discover such cases later (or users will report something related).