Skip to content

Making Test(Coroutine)Scope sealed breaks my entire test suite #3070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fluidsonic opened this issue Dec 7, 2021 · 1 comment
Closed

Making Test(Coroutine)Scope sealed breaks my entire test suite #3070

fluidsonic opened this issue Dec 7, 2021 · 1 comment
Assignees
Labels

Comments

@fluidsonic
Copy link

fluidsonic commented Dec 7, 2021

I have the following "scope" interface for all my integration tests (and similar in other kinds of tests):

interface IntegrationTestScope : TestCoroutineScope {
	val client: IntegrationTestClient
	val server: IntegrationTestServer
}

class IntegrationTestScopeImpl(
	override val client: IntegrationTestClient,
	coroutineScope: TestCoroutineScope,
	override val server: IntegrationTestServer,
) : IntegrationTestScope, TestCoroutineScope by coroutineScope

That is to keep TestCoroutineScope functionality in scope while also adding custom functionality.

In 1.6.0-RC that doesn't compile anymore.

Inheritance of sealed classes or interfaces from different module is prohibited

Same with the new TestScope.
What's the reason to make the old one suddenly sealed?
That's a source-breaking change. And it's not listed as a breaking change in the release notes.

The code of TestCoroutineScope has this @Deprecated comment:

Since 1.6.0, ERROR in 1.7.0 and removed as experimental in 1.8.0

Unfortunately it's already an error in 1.6.0 due to sealed.

What's the suggested path forward?

@fluidsonic fluidsonic changed the title Making Test(Coroutine)Scope breaks my entire test suite Making Test(Coroutine)Scope sealed breaks my entire test suite Dec 7, 2021
@dkhalanskyjb
Copy link
Collaborator

What's the reason to make the old one suddenly sealed?

The reason is that TestScope and TestCoroutineScope have very brittle behavior that could easily be broken by inheriting from them. For example, even before this, doing testScope.runBlockingTest would run the passed block not in the testScope but in a new scope with the same context. This significantly obscures the intent and the behavior of the code.

What's the suggested path forward?

We couldn't think of any use cases for someone inheriting from TestCoroutineScope. However, given that it causes breakage after all, maybe we should un-seal it in the next RC, given how it's deprecated anyway.

As for what can be done on your side, please see the migration guide: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md#testcoroutinescope In essence, if you use testScope.runBlockingTest, replace it with runBlockingTest(testScope.coroutineContext). Then, nothing in our API will accept the TestCoroutineScope as an argument, and you can just not implement TestCoroutineScope.

Does this work for you?

dkhalanskyjb added a commit that referenced this issue Dec 8, 2021
@dkhalanskyjb dkhalanskyjb self-assigned this Dec 8, 2021
woainikk pushed a commit that referenced this issue Dec 14, 2021
yorickhenning pushed a commit to yorickhenning/kotlinx.coroutines that referenced this issue Jan 28, 2022
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants