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

Disable/fix some tests on Windows #9811

Merged
merged 3 commits into from May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,27 +18,30 @@
import com.google.gwt.dev.jjs.ast.JTypeOracle;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
import com.google.gwt.thirdparty.guava.common.collect.Sets;
import com.google.gwt.thirdparty.guava.common.io.Files;

import junit.framework.TestCase;

import java.io.File;
import org.apache.commons.io.FileUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

/**
* Tests for {@link MinimalRebuildCacheManager}.
*/
public class MinimalRebuildCacheManagerTest extends TestCase {

public void testCacheChange() throws InterruptedException {
public void testCacheChange() throws InterruptedException, IOException {
String moduleName = "com.google.FooModule";
Map<String, String> initialCompilerOptions = ImmutableMap.of("option", "oldvalue");
PermutationDescription permutationDescription = new PermutationDescription();
File cacheDir = Files.createTempDir();
Path cacheDir = Files.createTempDirectory(null);

MinimalRebuildCacheManager minimalRebuildCacheManager =
new MinimalRebuildCacheManager(
TreeLogger.NULL, cacheDir, initialCompilerOptions);
TreeLogger.NULL, cacheDir.toFile(), initialCompilerOptions);

// Make sure we start with a blank slate.
minimalRebuildCacheManager.deleteCaches();
Expand All @@ -65,7 +68,7 @@ public void testCacheChange() throws InterruptedException {
Map<String, String> newCompilerOptions = ImmutableMap.of("option", "newvalue");
minimalRebuildCacheManager =
new MinimalRebuildCacheManager(
TreeLogger.NULL, cacheDir, newCompilerOptions);
TreeLogger.NULL, cacheDir.toFile(), newCompilerOptions);

// Now get the cache for FooModule under different compiler flags
MinimalRebuildCache fooCacheNew = minimalRebuildCacheManager.getCache(moduleName,
Expand All @@ -84,7 +87,7 @@ public void testCacheChange() throws InterruptedException {
// Switch back to the initial option values and verify you get the same old cache.
minimalRebuildCacheManager =
new MinimalRebuildCacheManager(
TreeLogger.NULL, cacheDir, initialCompilerOptions);
TreeLogger.NULL, cacheDir.toFile(), initialCompilerOptions);

// Now get the cache for FooModule under different under initial options values.
MinimalRebuildCache fooCacheResetOptions = minimalRebuildCacheManager.getCache(
Expand All @@ -96,16 +99,16 @@ public void testCacheChange() throws InterruptedException {
assertTrue(fooCacheOld.hasSameContent(fooCacheResetOptions));
minimalRebuildCacheManager.deleteCaches();
minimalRebuildCacheManager.shutdown();
cacheDir.delete();
FileUtils.deleteDirectory(cacheDir.toFile());
}

public void testReload() throws InterruptedException {
File cacheDir = Files.createTempDir();
public void testReload() throws InterruptedException, IOException {
Path cacheDir = Files.createTempDirectory(null);

String moduleName = "com.google.FooModule";
MinimalRebuildCacheManager minimalRebuildCacheManager =
new MinimalRebuildCacheManager(
TreeLogger.NULL, cacheDir, ImmutableMap.<String, String>of());
TreeLogger.NULL, cacheDir.toFile(), ImmutableMap.<String, String>of());
PermutationDescription permutationDescription = new PermutationDescription();

// Make sure we start with a blank slate.
Expand Down Expand Up @@ -149,7 +152,7 @@ public void testReload() throws InterruptedException {
// Start a new cache manager in the same folder.
MinimalRebuildCacheManager reloadedMinimalRebuildCacheManager =
new MinimalRebuildCacheManager(
TreeLogger.NULL, cacheDir, ImmutableMap.<String, String>of());
TreeLogger.NULL, cacheDir.toFile(), ImmutableMap.<String, String>of());

// Reread the previously saved cache.
MinimalRebuildCache reloadedCache =
Expand Down
Expand Up @@ -17,12 +17,13 @@

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
import com.google.gwt.thirdparty.guava.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributeView;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
Expand All @@ -32,21 +33,22 @@
*/
public class ClassPathEntryTest extends AbstractResourceOrientedTestBase {

/**
* This test will likely not work on Windows since directories that start with . are not
* implicitly hidden there. But since Java 6 does not have a File.setHidden() function, fixing
* this test for Windows is deferred till GWT officially depends on Java 7.
*/
public void testIgnoresHiddenDirectories() throws IOException {
// Setup a /tmp/.svn/ShouldNotBeFound.java folder structure.
File tempDir = Files.createTempDir();
File nestedHiddenDir = new File(tempDir, ".svn");
nestedHiddenDir.mkdir();
File javaFile = new File(nestedHiddenDir, "ShouldNotBeFound.java");
javaFile.createNewFile();
Path tempDir = Files.createTempDirectory(null);
Path nestedHiddenDir = tempDir.resolve(".svn");
Files.createDirectory(nestedHiddenDir);
Path javaFile = nestedHiddenDir.resolve("ShouldNotBeFound.java");
Files.createFile(javaFile);
// windows needs the hidden attribute to be set on file (not parent directory)
DosFileAttributeView hiddenAttr = Files.getFileAttributeView(javaFile,
DosFileAttributeView.class);
if (hiddenAttr != null) {
hiddenAttr.setHidden(true);
}

// Perform a class path directory inspection.
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir);
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir.toFile());
Map<AbstractResource, ResourceResolution> resources =
cpe.findApplicableResources(TreeLogger.NULL, createInclusivePathPrefixSet());

Expand All @@ -66,7 +68,7 @@ public void testResourceCreated() throws IOException, InterruptedException {
public void testForResourceListenerLeaks_pathPrefixSetIsCollected() throws Exception {
// Create a folder an initially empty folder.
PathPrefixSet pathPrefixSet = createInclusivePathPrefixSet();
DirectoryClassPathEntry classPathEntry = new DirectoryClassPathEntry(Files.createTempDir());
DirectoryClassPathEntry classPathEntry = new DirectoryClassPathEntry(Files.createTempDirectory(null).toFile());

// Show that we are not listening.
awaitFullGc();
Expand Down Expand Up @@ -94,7 +96,8 @@ public void testForResourceListenerLeaks_pathPrefixSetIsCollected() throws Excep
public void testForResourceListenerLeaks_classPathEntryIsCollected() throws Exception {
// Create a folder an initially empty folder.
PathPrefixSet pathPrefixSet = createInclusivePathPrefixSet();
DirectoryClassPathEntry classPathEntry = new DirectoryClassPathEntry(Files.createTempDir());
DirectoryClassPathEntry classPathEntry = new DirectoryClassPathEntry(
Files.createTempDirectory(null).toFile());

// Show that we are not listening.
awaitFullGc();
Expand Down Expand Up @@ -122,8 +125,8 @@ public void testForResourceListenerLeaks_classPathEntryIsCollected() throws Exce
public void testResourceCreated(Collection<PathPrefixSet> pathPrefixSets) throws IOException,
InterruptedException {
// Create a folder an initially empty folder.
File tempDir = Files.createTempDir();
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir);
Path tempDir = Files.createTempDirectory(null);
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir.toFile());

// Perform a class path directory inspection.
for (PathPrefixSet pathPrefixSet : pathPrefixSets) {
Expand All @@ -135,8 +138,8 @@ public void testResourceCreated(Collection<PathPrefixSet> pathPrefixSets) throws
}

// Create a file and give file events time to fire.
File createdFile = new File(tempDir, "Created.java");
createdFile.createNewFile();
Path createdFile = tempDir.resolve("Created.java");
Files.createFile(createdFile);
Thread.sleep(10);

// Perform a class path directory inspection.
Expand All @@ -161,10 +164,10 @@ public void testResourceDeleted() throws IOException, InterruptedException {
private void testResourceDeleted(Collection<PathPrefixSet> pathPrefixSets) throws IOException,
InterruptedException {
// Create a folder with one initial file, that can be deleted.
File tempDir = Files.createTempDir();
File fileToDelete = new File(tempDir, "ToDelete.java");
fileToDelete.createNewFile();
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir);
Path tempDir = Files.createTempDirectory(null);
Path fileToDelete = tempDir.resolve("ToDelete.java");
Files.createFile(fileToDelete);
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir.toFile());

// Perform a class path directory inspection.
for (PathPrefixSet pathPrefixSet : pathPrefixSets) {
Expand All @@ -177,7 +180,7 @@ private void testResourceDeleted(Collection<PathPrefixSet> pathPrefixSets) throw
}

// Delete the file and give file events time to fire.
fileToDelete.delete();
Files.delete(fileToDelete);
Thread.sleep(10);

// Perform a class path directory inspection.
Expand All @@ -201,10 +204,10 @@ public void testResourceRenamed() throws IOException, InterruptedException {
private void testResourceRenamed(Collection<PathPrefixSet> pathPrefixSets) throws IOException,
InterruptedException {
// Create a folder with one initial file, that can be renamed.
File tempDir = Files.createTempDir();
File fileToRename = new File(tempDir, "ToRename.java");
fileToRename.createNewFile();
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir);
Path tempDir = Files.createTempDirectory(null);
Path fileToRename = tempDir.resolve("ToRename.java");
Files.createFile(fileToRename);
DirectoryClassPathEntry cpe = new DirectoryClassPathEntry(tempDir.toFile());

// Perform class path directory inspections.
for (PathPrefixSet pathPrefixSet : pathPrefixSets) {
Expand All @@ -217,7 +220,7 @@ private void testResourceRenamed(Collection<PathPrefixSet> pathPrefixSets) throw
}

// Rename the file and give file events time to fire.
fileToRename.renameTo(new File(tempDir, "Renamed.java"));
Files.move(fileToRename, tempDir.resolve("Renamed.java"));
Thread.sleep(10);

for (PathPrefixSet pathPrefixSet : pathPrefixSets) {
Expand Down