Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3831

XWikiTempDir injects the same directory in all the fields and parameters resolved within the same millisecond

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 11.7-rc-1
    • None
    • Unknown

    Description

      What happens

      XWikiTempDirExtension injects XWikiTempDirUtil.createTemporaryDirectory() into every field and parameter annotated with @XWikiTempDir. That method names the directory target/test-<current time in milliseconds>, so all the directories requested within the same millisecond are the same directory, although its javadoc describes it as unique.

      In practice, a test class with several @XWikiTempDir fields (or a field and a parameter) usually gets the same directory in all of them, since they are injected one after the other in the same beforeEach. The test then silently shares files between what it expects to be separate directories.

      Found while writing tests for the remote observation module: the test base class emulates two XWiki instances and gives each one an @XWikiTempDir field as permanent directory. Both instances read and wrote the same observation/id.txt, so they had the same identifier and a test checking the cluster members passed without checking anything. The test was changed to create its own sub-directories, but any other test relying on several @XWikiTempDir injections is exposed to the same problem.

      Expected

      Each injection gets its own new directory, still under target. For example, keep the test-<time> prefix and add a counter or a random suffix, or use Files.createTempDirectory(Path.of("target"), "test-"), and make sure the returned directory did not exist before.

      Attachments

        Issue Links

          Activity

            People

              ciaens Clément Christiaens
              ciaens Clément Christiaens
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: