-
Notifications
You must be signed in to change notification settings - Fork 93
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
Unit tests should not store data in the .lemminx folder under the user's home directory. #1265
Comments
+1 |
It's difficult to know which tests may trigger the downloading behaviour, so the only way to be safe is to ensure all test suites use a different cache. Easiest way is probably something like : diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/AbstractCacheBasedTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/AbstractCacheBasedTest.java
index 51a4cf22..97fdd6c3 100644
--- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/AbstractCacheBasedTest.java
+++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/AbstractCacheBasedTest.java
@@ -21,6 +21,7 @@ import com.google.common.io.RecursiveDeleteOption;
import org.eclipse.lemminx.utils.FilesUtils;
import org.eclipse.lemminx.utils.ProjectUtils;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
/**
@@ -33,7 +34,6 @@ public abstract class AbstractCacheBasedTest {
@BeforeEach
public final void setupCache() throws Exception {
clearCache();
- System.setProperty(FilesUtils.LEMMINX_WORKDIR_KEY, TEST_WORK_DIRECTORY.toAbsolutePath().toString());
}
@AfterEach
@@ -41,7 +41,6 @@ public abstract class AbstractCacheBasedTest {
if (Files.exists(TEST_WORK_DIRECTORY)) {
MoreFiles.deleteDirectoryContents(TEST_WORK_DIRECTORY,RecursiveDeleteOption.ALLOW_INSECURE);
}
- System.clearProperty(FilesUtils.LEMMINX_WORKDIR_KEY);
FilesUtils.resetDeployPath();
}
}
\ No newline at end of file
diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java
index 86dcb797..12154179 100644
--- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java
+++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/FilesUtilsTest.java
@@ -31,6 +31,7 @@ public class FilesUtilsTest {
@Test
public void testFilesCachePathPreference() throws Exception {
+ String origWorkDir = System.getProperty(FilesUtils.LEMMINX_WORKDIR_KEY);
System.clearProperty(FilesUtils.LEMMINX_WORKDIR_KEY);
String newBasePathString = System.getProperty("user.home");
String newSubPathString = Paths.get("New", "Sub", "Path").toString();
@@ -38,6 +39,7 @@ public class FilesUtilsTest {
FilesUtils.setCachePathSetting(newBasePathString);
Path finalPath = FilesUtils.getDeployedPath(newSubPath);
assertEquals(Paths.get(newBasePathString, newSubPathString).toString(), finalPath.toString());
+ System.setProperty(FilesUtils.LEMMINX_WORKDIR_KEY, origWorkDir);
}
@Test
diff --git a/pom.xml b/pom.xml
index 2410dd21..72c7eabb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -133,6 +133,7 @@
<version>3.0.0-M4</version>
<configuration>
<runOrder>random</runOrder>
+ <argLine>-Dlemminx.workdir=${project.build.directory}/test-cache/</argLine>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<disable>false</disable>
<usePhrasedFileName>false</usePhrasedFileName> The problem is those running the tests through an IDE (eg. Eclipse) would also need to make sure that property is set in the test launch configuration. |
datho7561
added a commit
to datho7561/lemminx
that referenced
this issue
Aug 31, 2022
datho7561
added a commit
to datho7561/lemminx
that referenced
this issue
Sep 2, 2022
angelozerr
changed the title
Unit tests should not store data in ~/.lemminx
Unit tests should not store data in the .lemminx folder under the user's home directory.
Oct 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unit tests currently write data in ~/.lemminx, this is wrong:
Tests should use a clean cache directory, that would not pollute the user cache and also ensure idempotency
The text was updated successfully, but these errors were encountered: