Skip to content

Fix JavaLocalLambdaRunConfigurationIntegrationTest integ tests #4549

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 62 commits into from
Jul 10, 2024

Conversation

vchikoti1998
Copy link
Contributor

@vchikoti1998 vchikoti1998 commented Jun 5, 2024

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Description

The gradle instance in the test should be configured to use a different user home than the instance of gradle running the test

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vchikoti1998 vchikoti1998 requested a review from a team as a code owner June 5, 2024 03:56
@vchikoti1998
Copy link
Contributor Author

vchikoti1998 commented Jun 5, 2024

/runIntegrationTest

@@ -18,7 +18,7 @@ kotlin.code.style=official
# Gradle settings
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx4096m
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Contributor Author

@vchikoti1998 vchikoti1998 Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified for testing, may be this is an issue, but it doesn't appear to be.
reverting this change

@vchikoti1998 vchikoti1998 mentioned this pull request Jun 5, 2024
5 tasks
}

private fun createGradlePropertiesFile(gradleUserHome: File) {
val gradlePropertiesFile = File(gradleUserHome, "gradle.properties")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be the project root? how would a gradle instance discover this location if the configuration is self-referential with nothing outside referencing it?

gradlePropertiesFile.writeText(
"""
org.gradle.jvmargs=-Xmx4096m
gradle.user.home=${gradleUserHome.absolutePath}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something that is also unclear at the moment is if we are actually allowed to modify the user home in this manner, or if this is too late because gradle has already selected a user home

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in this case shall we try using Env Variable GRADLE_USER_HOME, so it can be set before Gradle initializes.
will test this out

@vchikoti1998
Copy link
Contributor Author

vchikoti1998 commented Jun 12, 2024

/retryBuilds

@vchikoti1998
Copy link
Contributor Author

This is rider IntegrationTest error:

Execution failed for task ':plugin-toolkit:jetbrains-rider:integrationTest'.
> Process 'Gradle Test Executor 2' finished with non-zero exit value 1

will work on separate PR

@@ -4,13 +4,16 @@
package software.aws.toolkits.jetbrains.services.lambda.steps

import com.intellij.execution.configurations.GeneralCommandLine
import org.junit.AfterClass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is in the src tree, which generally means it is not appropriate to reference any libraries that are used in tests. in an upcoming PR, we pull in some build system improvements that remove a lot of test libraries from the classpath, which will make this harder to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will provide in the test class

@@ -24,12 +27,14 @@ data class BuildLambdaRequest(

class BuildLambda(private val request: BuildLambdaRequest) : SamCliStep() {
override val stepName: String = message("lambda.create.step.build")
private val buildEnvVars = mapOf("GRADLE_USER_HOME" to gradleUserHomeDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we always want to set the Gradle home directory to a temp directory. this should only be set if configured by a test

@vchikoti1998
Copy link
Contributor Author

as discussed offline:

  1. looking at the documentation for SAM build to see if there is another way to pass the Gradle user home environment variable without modifying the run configuration.

  2. If no alternative method is found, figure out to proceed to modify the existing run configuration to include the Gradle user home environment variable.

@@ -95,6 +98,7 @@ class JavaLocalLambdaRunConfigurationIntegrationTest(private val runtime: Lambda
fun tearDown() {
CompilerTestUtil.disableExternalCompiler(projectRule.project)
MockCredentialsManager.getInstance().reset()
File(gradleUserHomeDir).deleteRecursively()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is in the temp directory, do we still need to cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted changes, since we doesn't required temp dir

@@ -103,7 +107,9 @@ class JavaLocalLambdaRunConfigurationIntegrationTest(private val runtime: Lambda
project = projectRule.project,
runtime = runtime.toSdkRuntime(),
input = "\"Hello World\"",
credentialsProviderId = mockId
credentialsProviderId = mockId,
environmentVariables = mutableMapOf("GRADLE_USER_HOME" to gradleUserHomeDir),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted changes

credentialsProviderId = mockId
credentialsProviderId = mockId,
environmentVariables = mutableMapOf("GRADLE_USER_HOME" to gradleUserHomeDir),
samOptions = SamOptions(buildInContainer = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why we need to build in container? why would we want to do one over the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, making it run in a containerized environment doesn't require env vars to be set The test case passed since container has its own grade user home dir.

@@ -102,6 +102,10 @@ fun GeneralCommandLine.samBuildCommand(
addParameter(buildDir.toString())
if (samOptions.buildInContainer) {
withParameters("--use-container")
environmentVariables.forEach { (key, value) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure it's a good idea for the container environment to always inherit these

@@ -36,9 +36,11 @@ fun createTemplateRunConfiguration(
inputIsFile: Boolean = false,
credentialsProviderId: String? = null,
region: AwsRegion? = getDefaultRegion(),
environmentVariables: MutableMap<String, String> = mutableMapOf(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it need to be mutable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted these changes

@vchikoti1998 vchikoti1998 changed the title Testing JavaLocalLambdaRunConfigurationIntegrationTest integ tests Fix JavaLocalLambdaRunConfigurationIntegrationTest integ tests Jun 25, 2024
@vchikoti1998
Copy link
Contributor Author

Building in a container ensures the build environment matches the AWS Lambda runtime, reducing runtime errors and improving deployment consistency. This is essential when local runtimes or dependencies differ from those required by Lambda. In addition, containerized builds can provide isolated environments that avoid conflicts with other local dependencies or configurations.

Copy link

@vchikoti1998 vchikoti1998 merged commit f97e9be into main Jul 10, 2024
12 of 16 checks passed
@vchikoti1998 vchikoti1998 deleted the vchikoti/javaLocalLambdaRunConfigInteg_Test branch July 10, 2024 22:58
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

Successfully merging this pull request may close these issues.

2 participants