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
- is related to
-
XCOMMONS-1685 Add a Junit5 extension to create a temporary directory
-
- Closed
-