-
-
Notifications
You must be signed in to change notification settings - Fork 56
ADFA-5052: Defer eager JavaCompilerService construction until a real .java file is touched #1637
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
Draft
davidschachterADFA
wants to merge
10
commits into
stage
Choose a base branch
from
task/ADFA-5052-lazy-load-java-compiler
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d9356d
ADFA-5052: Defer JavaCompilerService/SourceFileManager construction u…
davidschachterADFA ad09be1
ADFA-5052: Serialize the deferred javac reset against concurrent acce…
davidschachterADFA e9a54b4
ADFA-5052: Fix exception handling, analyze() bypass, and a narrow pos…
davidschachterADFA 23094e0
Merge branch 'stage' into task/ADFA-5052-lazy-load-java-compiler
davidschachterADFA d0a8cc9
Merge branch 'stage' into task/ADFA-5052-lazy-load-java-compiler
davidschachterADFA 33d20fa
ADFA-5052: Make shutdown terminal, and cover the lifecycle transitions
davidschachterADFA 9236c4b
ADFA-5052: Revert fixtures I should not have committed, and close thr…
davidschachterADFA a7c49e6
ADFA-5052: Revert the regenerated sync fixtures again
davidschachterADFA 2dd76f2
Merge branch 'stage' into task/ADFA-5052-lazy-load-java-compiler
davidschachterADFA 1bec5b7
Merge branch 'stage' into task/ADFA-5052-lazy-load-java-compiler
davidschachterADFA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
lsp/java/src/test/java/com/itsaky/androidide/lsp/java/JavaLanguageServerLifecycleTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * AndroidIDE is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.itsaky.androidide.lsp.java | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import io.mockk.mockk | ||
| import org.junit.After | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| /** | ||
| * ADFA-5052 defers the javac reset to the first real Java interaction, which makes the server's | ||
| * lifecycle something with states rather than a single construction. These cover the transitions | ||
| * that do not need a project fixture; the concurrent ones (an operation holding a compiler while | ||
| * shutdown lands) are ADFA-5261. | ||
| */ | ||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(manifest = Config.DEFAULT_VALUE_STRING) | ||
| class JavaLanguageServerLifecycleTest { | ||
| // Every server registers itself on the global EventBus and adds indexing services to the | ||
| // ProjectManagerImpl singleton in its init block, and Robolectric caches a sandbox per @Config -- | ||
| // so a server left running here would keep receiving events posted by other test classes. | ||
| private val servers = mutableListOf<JavaLanguageServer>() | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| servers.forEach { it.shutdown() } | ||
| servers.clear() | ||
| } | ||
|
|
||
| private fun newServer() = JavaLanguageServer().also { servers += it } | ||
|
|
||
| // The whole point of the deferral: nothing javac-related is built until a Java file is touched, | ||
| // so shutting down before that must be a no-op rather than a teardown of things never made. | ||
| @Test | ||
| fun `shutdown before the first java interaction is safe`() { | ||
| val server = newServer() | ||
|
|
||
| server.shutdown() | ||
|
|
||
| assertThat(server.isShutDown).isTrue() | ||
| } | ||
|
|
||
| // A server whose javac state has been destroyed does not come back because a project opened | ||
| // afterwards -- otherwise it rebuilds compilers that nothing will shut down again. | ||
| @Test | ||
| fun `a project opened after shutdown does not revive the server`() { | ||
| val server = newServer() | ||
| server.shutdown() | ||
|
|
||
| server.setupWithProject(mockk(relaxed = true)) | ||
|
|
||
| assertThat(server.isShutDown).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a fresh server is not shut down`() { | ||
| assertThat(newServer().isShutDown).isFalse() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.