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

fix failing unit tests in gradle-plugin/it module #3406

Open
1 task
rohanKanojia opened this issue Sep 25, 2024 · 11 comments
Open
1 task

fix failing unit tests in gradle-plugin/it module #3406

rohanKanojia opened this issue Sep 25, 2024 · 11 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@rohanKanojia
Copy link
Member

Component

None

Task description

Component

Gradle Plugin Integration Tests

Task description

Description

Related to #1338

⚠️ A windows machine is required to reproduce and fix problems in this issue

When executing mvn clean install on Windows, the following unit tests are failing in gradle-plugin/it module:

Error:  Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.004 s <<< FAILURE! -- in org.eclipse.jkube.gradle.plugin.tests.TriggersAnnotationIT
Error:  org.eclipse.jkube.gradle.plugin.tests.TriggersAnnotationIT.ocResourceTask_whenRun_generatesOpenShiftManifestWithTriggersAnnotation -- Time elapsed: 0.457 s <<< ERROR!
java.lang.IllegalArgumentException: 
Values not equal for entry: 'image.openshift.io/triggers', expected '[ {
  "from" : {
    "kind" : "ImageStreamTag",
    "name" : "triggersannotation:latest"
  },
  "fieldPath" : "spec.template.spec.containers[?(@.name==\"orgeclipsejkubeintegrationtestsgradle-triggersannotation\")].image"
} ]' but was '[ {
  "from" : {
    "kind" : "ImageStreamTag",
    "name" : "triggersannotation:latest"
  },
  "fieldPath" : "spec.template.spec.containers[?(@.name==\"orgeclipsejkubeintegrationtestsgradle-triggersannotation\")].image"
} ]'
Error:  Errors: 
Error:    ConfigMapIT.k8sResource_whenRun_generatesK8sManifestsContainingConfigMap:37 � IllegalArgument Values not equal for entry: 'application.properties', expected 'environment = test
foo = bar' but was 'environment = test
foo = bar'
Error:    ConfigMapIT.ocResource_whenRun_generatesOpenShiftManifestsContainingConfigMap:56 � IllegalArgument Values not equal for entry: 'application.properties', expected 'environment = test
foo = bar' but was 'environment = test
foo = bar'
Error:    DependencyResourcesIT.k8sResource_whenRun_generatesK8sManifestsIncludingDependencies:36 � UnexpectedBuildFailure Unexpected build execution failure in D:\a\jkube-build-testing\jkube-build-testing\jkube\gradle-plugin\it\src\it\dependency-resources with arguments [-PjKubeVersion=null, --console=plain, clean, jar, k8sResource, --stacktrace]
Error:    FileSecretIT.k8sResource_whenRun_generatesK8sSecret:35 � IllegalArgument Values not equal for entry: 'application.properties', expected 'a2V5MSA9IHZhbHVlMQprZXkyID0gdmFsdWUyCmtleTMgPSB2YWx1ZTM=' but was 'a2V5MSA9IHZhbHVlMQ0Ka2V5MiA9IHZhbHVlMg0Ka2V5MyA9IHZhbHVlMw=='
Error:    FileSecretIT.ocResource_whenRun_generatesK8sSecret:48 � IllegalArgument Values not equal for entry: 'application.properties', expected 'a2V5MSA9IHZhbHVlMQprZXkyID0gdmFsdWUyCmtleTMgPSB2YWx1ZTM=' but was 'a2V5MSA9IHZhbHVlMQ0Ka2V5MiA9IHZhbHVlMg0Ka2V5MyA9IHZhbHVlMw=='
Error:    KubernetesExtensionIT.k8sConfigView_containsAFullyDeserializedConfiguration:39 � Validation EndsWithValidationMatcher failed for field 'resourcetargetdirectory'. Received value is 'D:\a\jkube-build-testing\jkube-build-testing\jkube\gradle-plugin\it\src\it\extension-configuration\build\META-INF\jkube', control value is 'extension-configuration/build/META-INF/jkube'.
Error:    TriggersAnnotationIT.ocResourceTask_whenRun_generatesOpenShiftManifestWithTriggersAnnotation:53 � IllegalArgument Values not equal for entry: 'image.openshift.io/triggers', expected '[ {
  "from" : {
    "kind" : "ImageStreamTag",
    "name" : "triggersannotation:latest"
  },
  "fieldPath" : "spec.template.spec.containers[?(@.name==\"orgeclipsejkubeintegrationtestsgradle-triggersannotation\")].image"
} ]' but was '[ {
  "from" : {
    "kind" : "ImageStreamTag",
    "name" : "triggersannotation:latest"
  },
  "fieldPath" : "spec.template.spec.containers[?(@.name==\"orgeclipsejkubeintegrationtestsgradle-triggersannotation\")].image"
} ]'
[INFO] 
Error:  Tests run: 220, Failures: 0, Errors: 7, Skipped: 0

I think we need to adapt these tests in order to make them work on windows:

  • TriggersAnnotationIT
  • FileSecretIT
  • DependencyResourcesIT
  • ConfigMapIT

Expected Behavior

All unit tests in gradle-plugin/it module should pass on windows

Acceptance Criteria

  • Build completes successfully on windows for gradle-plugin/it module
@rohanKanojia rohanKanojia added good first issue Good for newcomers help wanted Extra attention is needed labels Sep 25, 2024
@rexrk
Copy link
Contributor

rexrk commented Sep 30, 2024

Hi, I want to contribute to this issue.

@rexrk
Copy link
Contributor

rexrk commented Oct 3, 2024

Hello I am stuck with DependencyResourcesIT, as both the test cases runs successfully if executed individually but fails when running as whole. It seems execution of one test case locks some files in build dir making other test case to fail. what should be the approach to tackle it, kindly guide me.

`Execution failed for task ':dependency:clean'.

java.io.IOException: Unable to delete directory '{dir}\gradle-plugin\it\src\it\dependency-resources\dependency\build'
Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.`

@rexrk
Copy link
Contributor

rexrk commented Oct 10, 2024

@rohanKanojia

@rohanKanojia
Copy link
Member Author

@rexrk : Sorry, I missed this notification.

I'll try to check this on my personal windows machine this weekend.

Is it possible for you to create pull request for integration tests that you managed to fix?

@rexrk
Copy link
Contributor

rexrk commented Oct 11, 2024

@rohanKanojia I am unsure about other ones as well, is this correct fix as the error is showing
expected value is :

application.properties: a2V5MSA9IHZhbHVlMQ0Ka2V5MiA9IHZhbHVlMg0Ka2V5MyA9IHZhbHVlMw==
and value in expected/yaml found is :
application.properties: a2V5MSA9IHZhbHVlMQprZXkyID0gdmFsdWUyCmtleTMgPSB2YWx1ZTM=
Do I need to change in the expected yaml as the error is saying to?

@rohanKanojia
Copy link
Member Author

DependencyResourceIT seems to be failing due to a race condition between the two tests, gradle clean fails with directory not empty error. If we make them ordered tests it seems to pass.

TriggersAnnotationIT is failing due to windows line breaks added to annotation in TriggersAnnotationEnricher. Modifying below line to this makes it pass

return Serialization.asJson(triggerList).replaceAll("\r\n", "\n")

ConfigMapIT and FileSecretIT are failing due to a similar reason.

I suggest breaking this issue down into smaller issues per test failures.

@manusa
Copy link
Member

manusa commented Oct 16, 2024

DependencyResourceIT seems to be failing due to a race condition between the two tests, gradle clean fails with directory not empty error. If we make them ordered tests it seems to pass.

Rather than make the tests follow a strict order, we should decouple them

@rexrk
Copy link
Contributor

rexrk commented Oct 16, 2024

@rohanKanojia @manusa yes as i already tried ordering with @order() annotation but it still was failing.

@rohanKanojia
Copy link
Member Author

@rexrk : I also had to remove clean from gradle instruction.

I found a better way to fix this issue without splitting the test. We can avoid conflict by instructing jkube to generate resources in a different directory:

diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/DependencyResourcesIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/DependencyResourcesIT.java
index 0792d7d0e..8d1012149 100644
--- a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/DependencyResourcesIT.java
+++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/DependencyResourcesIT.java
@@ -32,7 +32,7 @@ class DependencyResourcesIT {
   void k8sResource_whenRun_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
     // When
     final BuildResult result = gradleRunner.withITProject("dependency-resources")
-        .withArguments("clean", "jar", "k8sResource", "--stacktrace")
+        .withArguments("jar", "k8sResource", "--stacktrace")
         .build();
     // Then
     ResourceVerify.verifyResourceDescriptors(
@@ -49,12 +49,12 @@ class DependencyResourcesIT {
   void k8sResource_whenRunWithReplicas_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
     // When
     final BuildResult result = gradleRunner.withITProject("dependency-resources")
-        .withArguments("-Pjkube.replicas=1337", "clean", "jar", "k8sResource", "--stacktrace")
+        .withArguments("-Pjkube.targetDir=build/classes/java/main/META-INF/jkube-replicas-override", "-Pjkube.replicas=1337",  "jar", "k8sResource", "--stacktrace")
         .build();
     // Then
     ResourceVerify.verifyResourceDescriptors(
         gradleRunner.resolveFile("dependent", "build", "classes", "java", "main",
-            "META-INF", "jkube", "kubernetes.yml"),
+            "META-INF", "jkube-replicas-override", "kubernetes.yml"),
         gradleRunner.resolveFile("expected", "kubernetes-with-replica-override.yml"));
     assertThat(result).extracting(BuildResult::getOutput).asString()
         .contains("Using resource templates from")

@rohanKanojia
Copy link
Member Author

rohanKanojia commented Oct 20, 2024

I've created these issues to break down this task:

@rexrk
Copy link
Contributor

rexrk commented Oct 22, 2024

@rohanKanojia this DependencyResource fix seems more straight forward approach ! Kudos and thanks 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants