-
-
Notifications
You must be signed in to change notification settings - Fork 24
ADFA-2092: gradle sync error during initialization is incorrectly reported as success #648
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
505340a
fix: initialization failures are incorrectly reported as success
itsaky-adfa b7f6c2c
fix: consider sync file readability when deciding whether to sync
itsaky-adfa 50ffdf0
Merge branch 'stage' into fix/ADFA-2092
itsaky-adfa 979a83b
fix: inverted condition check for areSyncFilesReadable
itsaky-adfa 51af035
fix: missing notifyBuildSuccess call
itsaky-adfa 78b7ed6
Merge branch 'stage' into fix/ADFA-2092
itsaky-adfa 0cc0759
Merge branch 'stage' into fix/ADFA-2092
itsaky-adfa 148bcef
Merge branch 'stage' into fix/ADFA-2092
itsaky-adfa 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
122 changes: 122 additions & 0 deletions
122
...ing-api-impl/src/test/java/com/itsaky/androidide/tooling/impl/ToolingApiServerImplTest.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,122 @@ | ||
| package com.itsaky.androidide.tooling.impl | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import com.itsaky.androidide.tooling.api.messages.InitializeProjectParams | ||
| import com.itsaky.androidide.tooling.api.messages.result.InitializeResult | ||
| import com.itsaky.androidide.tooling.api.messages.result.TaskExecutionResult | ||
| import com.itsaky.androidide.tooling.api.messages.result.isSuccessful | ||
| import com.itsaky.androidide.tooling.api.sync.ProjectSyncHelper | ||
| import com.itsaky.androidide.tooling.impl.sync.RootModelBuilder | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.mockkObject | ||
| import io.mockk.spyk | ||
| import io.mockk.verify | ||
| import org.gradle.tooling.GradleConnector | ||
| import org.gradle.tooling.ProjectConnection | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.junit.runners.JUnit4 | ||
| import java.io.File | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| /** | ||
| * @author Akash Yadav | ||
| */ | ||
| @RunWith(JUnit4::class) | ||
| class ToolingApiServerImplTest { | ||
|
|
||
| private fun testInitParams( | ||
| directory: String = "/does/not/exist", | ||
| forceSync: Boolean = false, | ||
| ) = InitializeProjectParams( | ||
| directory = directory, needsGradleSync = forceSync | ||
| ) | ||
|
|
||
| private data class MockServer( | ||
| val server: ToolingApiServerImpl, | ||
| val connector: GradleConnector, | ||
| val connection: ProjectConnection | ||
| ) | ||
|
|
||
| private fun mockkToolingServer(): MockServer { | ||
| val server = spyk(ToolingApiServerImpl()) | ||
| val connector = mockk<GradleConnector>(relaxed = true) | ||
| val connection = mockk<ProjectConnection>(relaxed = true) | ||
|
|
||
| // ensure that we do not start actual Gradle build | ||
| every { | ||
| server.getOrConnectProject( | ||
| projectDir = any(), forceConnect = true, initParams = any(), gradleDist = any() | ||
| ) | ||
| } returns (connector to connection) | ||
|
|
||
| return MockServer(server, connector, connection) | ||
| } | ||
|
|
||
| @Test | ||
| fun `GIVEN any initialization params WHEN project init fails THEN report as failure`() { | ||
|
|
||
| mockkObject(RootModelBuilder) | ||
| every { | ||
| // Simulate a Gradle sync failure | ||
| RootModelBuilder.build( | ||
| any(), any() | ||
| ) | ||
| } throws RuntimeException("intentional failure") | ||
|
|
||
| val (server) = mockkToolingServer() | ||
|
|
||
| every { | ||
| // ensure we don't fail on non-existent project directory | ||
| server.validateProjectDirectory(any()) | ||
| } returns null | ||
|
|
||
| val result = server.initialize(testInitParams()).get(5, TimeUnit.SECONDS) | ||
| assertThat(result).isNotNull() | ||
| assertThat(result.isSuccessful).isFalse() | ||
| assertThat(result).isInstanceOf(InitializeResult.Failure::class.java) | ||
|
|
||
| // unknown error because of the mocked runtime exception | ||
| assertThat((result as InitializeResult.Failure).failure).isEqualTo(TaskExecutionResult.Failure.UNKNOWN) | ||
| } | ||
|
|
||
| @Test | ||
| fun `GIVEN force sync not requested WHEN sync files are unreadable THEN sync anyway`() { | ||
|
|
||
| val initParams = testInitParams(forceSync = false) | ||
| val cacheFile = ProjectSyncHelper.cacheFileForProject(File(initParams.directory)) | ||
|
|
||
| mockkObject(RootModelBuilder) | ||
| every { | ||
| // simulate a successful cache write | ||
| RootModelBuilder.build( | ||
| any(), any() | ||
| ) | ||
| } returns cacheFile | ||
|
|
||
| mockkObject(ProjectSyncHelper) | ||
| every { | ||
| // simulate unreadable cache files | ||
| ProjectSyncHelper.areSyncFilesReadable(any(), any()) | ||
| } returns false | ||
|
|
||
| val (server) = mockkToolingServer() | ||
|
|
||
| every { | ||
| // ensure we don't fail on non-existent project directory | ||
| server.validateProjectDirectory(any()) | ||
| } returns null | ||
|
|
||
| val result = server.initialize(initParams).get(5, TimeUnit.SECONDS) | ||
| assertThat(result).isNotNull() | ||
| assertThat(result.isSuccessful).isTrue() | ||
| assertThat(result).isInstanceOf(InitializeResult.Success::class.java) | ||
| assertThat((result as InitializeResult.Success).cacheFile).isEqualTo(cacheFile) | ||
|
|
||
| verify(exactly = 1) { | ||
| // ensure gradle sync was requested | ||
| RootModelBuilder.build(initParams, any()) | ||
| } | ||
| } | ||
| } | ||
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.