Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48945

Testreport lacks of those test in which the hashcode of two different testsuite name coincide

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • xunit-plugin
    • None
    • Jenkins ver. 2.89.2
      xUnit-Version: 1.102
      Jdk:1.8.0_151
      Os: Ubuntu 14.04.5 LTS

      The published testreport generated by xunit is wrong, if two testname files will result in the same hashcode.

      the class org.jenkinsci.plugins.xunit.service.XUnitConversionService uses the following logic, to create temporarily junit-xml files:

      File junitTargetFile = new File(parent, JUNIT_FILE_PREFIX + inputFile.hashCode() + JUNIT_FILE_POSTFIX);

      in my project, i have two Testclasses that produce the same hash-code.

      de.congstar.acceptancetests.aax.templates.komplett.EKOM02XTest
      de.congstar.acceptancetests.aax.templates.komplett.EKOM039Test

      the temp. generated junit-file for both source junit xml files was:
      generatedJUnitFiles/JUnit/TEST-747423851.xml

      that occurrs only on the jenkins server that runs on linux - on my local windows pc, the hashcollision does not occurr.

      as a result of this name-clash only the results of the last Testclass is reported to jenkins.

          [JENKINS-48945] Testreport lacks of those test in which the hashcode of two different testsuite name coincide

          it took some amount of time, to track down the problem - could just anyone take a look at this issue?

          Sascha Friederich added a comment - it took some amount of time, to track down the problem - could just anyone take a look at this issue?

          Nikolas Falco added a comment -

          Change priority since an easy workaround exists, rename one of test adding a character like _

          Are you running JUnit tests?

          Nikolas Falco added a comment - Change priority since an easy workaround exists, rename one of test adding a character like _ Are you running JUnit tests?

          Sascha Friederich added a comment - - edited

          Thanx for responding

          >Are you running JUnit tests?
          yes, we are running junit-tests.

          yes, renaming would be a workaround - but we have more than 1000 unit tests und unfortunately the hashcollsion is silent, so we dont know if it happens again (with other filenames)

          i think a simple check, if the generated target file name exists (and then choosing a different name) would be fix.

          File junitTargetFile = new File(parent, JUNIT_FILE_PREFIX + inputFile.hashCode() + JUNIT_FILE_POSTFIX);
          while (junitTargetFile.exists()) {
              junitTargetFile = new File(parent, JUNIT_FILE_PREFIX + inputFile.hashCode()+"_"+ RandomStringUtils.randomAlphabetic(1) + JUNIT_FILE_POSTFIX);
          }
          ...
          //this method does not check, if the targetFile already exists.
          inputMetric.convert(inputFile, junitTargetFile);
          

           

          Sascha Friederich added a comment - - edited Thanx for responding >Are you running JUnit tests? yes, we are running junit-tests. yes, renaming would be a workaround - but we have more than 1000 unit tests und unfortunately the hashcollsion is silent, so we dont know if it happens again (with other filenames) i think a simple check, if the generated target file name exists (and then choosing a different name) would be fix. File junitTargetFile = new File(parent, JUNIT_FILE_PREFIX + inputFile.hashCode() + JUNIT_FILE_POSTFIX); while (junitTargetFile.exists()) { junitTargetFile = new File(parent, JUNIT_FILE_PREFIX + inputFile.hashCode()+ "_" + RandomStringUtils.randomAlphabetic(1) + JUNIT_FILE_POSTFIX); } ... // this method does not check, if the targetFile already exists. inputMetric.convert(inputFile, junitTargetFile);  

          Nikolas Falco added a comment -

          Ok, I was interested to make a proper unit test (also if hascode of file object depends from absolute path so depends from O.S. and your jenkins workspace path).

          I'm already working on solution that is similar to yours but using UUID

          Nikolas Falco added a comment - Ok, I was interested to make a proper unit test (also if hascode of file object depends from absolute path so depends from O.S. and your jenkins workspace path). I'm already working on solution that is similar to yours but using UUID

          Code changed in jenkins
          User: Nikolas Falco
          Path:
          src/main/java/org/jenkinsci/plugins/xunit/XUnitDefaultValues.java
          src/main/java/org/jenkinsci/plugins/xunit/service/XUnitConversionService.java
          src/main/java/org/jenkinsci/plugins/xunit/service/XUnitTransformer.java
          src/main/java/org/jenkinsci/plugins/xunit/types/CustomType.java
          src/test/java/org/jenkinsci/plugins/xunit/service/XUnitConversionServiceTest.java
          src/test/java/org/jenkinsci/plugins/xunit/service/XUnitTransformerTest.java
          http://jenkins-ci.org/commit/xunit-plugin/2885f4f57ceaa1e816db07ca414285935b83c783
          Log:
          JENKINS-48945 Testreport lacks of those test in which the hashcode of two different testsuite name coincide

          Use UUID instead the hashcode of the file to generate a unique converted test report.
          By default java provides a version 4 UUID that ensure be unique in the same JVM instance. Since there are no more JVM that works with the same workspace is enough. A version 1 UUID that use MAC address to ensure file is unique over Jenkins nodes is not needed since XUnitProcessor does not copy slave node report files back to master.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Nikolas Falco Path: src/main/java/org/jenkinsci/plugins/xunit/XUnitDefaultValues.java src/main/java/org/jenkinsci/plugins/xunit/service/XUnitConversionService.java src/main/java/org/jenkinsci/plugins/xunit/service/XUnitTransformer.java src/main/java/org/jenkinsci/plugins/xunit/types/CustomType.java src/test/java/org/jenkinsci/plugins/xunit/service/XUnitConversionServiceTest.java src/test/java/org/jenkinsci/plugins/xunit/service/XUnitTransformerTest.java http://jenkins-ci.org/commit/xunit-plugin/2885f4f57ceaa1e816db07ca414285935b83c783 Log: JENKINS-48945 Testreport lacks of those test in which the hashcode of two different testsuite name coincide Use UUID instead the hashcode of the file to generate a unique converted test report. By default java provides a version 4 UUID that ensure be unique in the same JVM instance. Since there are no more JVM that works with the same workspace is enough. A version 1 UUID that use MAC address to ensure file is unique over Jenkins nodes is not needed since XUnitProcessor does not copy slave node report files back to master.

          Thank You  for solving this issue so fast

          Sascha Friederich added a comment - Thank You  for solving this issue so fast

          is there a plan, when this bugfix will be released? (its not part of Version: 1.103)

          Sascha Friederich added a comment - is there a plan, when this bugfix will be released? (its not part of Version: 1.103)

            nfalco Nikolas Falco
            sascha_friederich Sascha Friederich
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: