Skip to content
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

Support running KSP tests in parallel #359

Open
ansman opened this issue Mar 12, 2023 · 2 comments
Open

Support running KSP tests in parallel #359

ansman opened this issue Mar 12, 2023 · 2 comments

Comments

@ansman
Copy link
Contributor

ansman commented Mar 12, 2023

This issue might actually be related to KSP itself, but in my project auto-dagger I run my tests concurrently using Junit 5. This works fine for tests that use a regular annotation processor but fails for KSP tests (you essentially get a bunch of errors during type resolution like org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException: Descriptor wasn't found for declaration CLASS).

To repro, comment out this line: https://github.com/ansman/auto-dagger/blob/main/compiler/src/test/kotlin/se/ansman/dagger/auto/compiler/KspTest.kt#L6
And then run the tests.

Again this issue might be with KSP and if so please just close this issue and I'll open an issue with KSP.

@tschuchortdev
Copy link
Owner

I'm surprised that it works at all. KotlinCompilation uses a thread-local singleton object to register KAPT processors, ComponentRegistrars and so on, since the compiler can only find them through classpath scanning. Parallel execution should thus always come with a risk of race conditions unless you can guarantee a dedicated thread per compilation. Does the KSP source code itself use parallel test execution?

@ansman
Copy link
Contributor Author

ansman commented Mar 12, 2023

Since it's all synchronous otherwise I think each test would run in a dedicated thread. But the threads would probably be reused but that must work or it wouldn't work running multiple tests.

I spawn no new threads in my processor or tests. In fact I didn't even think it was possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants