Skip to content

Commit

Permalink
fix test concurrency issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jun 30, 2024
1 parent 63d52e7 commit 953b663
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@
public class TestFile {

public static void main(String[] args) throws IOException {
new File("build/test").mkdirs();
FileWriter writer = new FileWriter("build/test/test.txt", StandardCharsets.UTF_8);
var temp = Files.createTempFile("temp", "txt");
Files.deleteIfExists(temp);
FileWriter writer = new FileWriter(temp.toAbsolutePath().toString(), StandardCharsets.UTF_8);
writer.write("Hello World!\n");
writer.close();

FileWriter writer2 = new FileWriter(new File("build/test/test.txt"), StandardCharsets.UTF_8, true);
FileWriter writer2 = new FileWriter(temp.toFile(), StandardCharsets.UTF_8, true);
writer2.write("Goodbye World!");
writer2.close();

FileReader reader = new FileReader("build/test/test.txt", StandardCharsets.UTF_8);
FileReader reader = new FileReader(temp.toAbsolutePath().toString(), StandardCharsets.UTF_8);
StringBuilder sb = new StringBuilder();
int c;
while ((c = reader.read()) != -1) {
sb.append((char) c);
}
reader.close();
System.out.println(sb.toString());
Files.deleteIfExists(temp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package xyz.wagyourtail.jvmdg.util

import org.apache.commons.compress.archivers.zip.ZipFile
import org.gradle.api.JavaVersion
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainSpec
import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.ClassNode
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/xyz/wagyourtail/jvmdg/test/ClassRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -104,7 +105,7 @@ public static Stream<Arguments> arguments() throws IOException {
.unwrap();
}

private static final Map<String, Map.Entry<Integer, String>> originalResults = new HashMap<>();
private static final Map<String, Map.Entry<Integer, String>> originalResults = new ConcurrentHashMap<>();

@BeforeAll
public static void runOriginal() throws IOException, InterruptedException {
Expand All @@ -128,7 +129,7 @@ public static void runOriginal() throws IOException, InterruptedException {
}
}

private static final Map<FlagsAndRunner, Path> downgradedPaths = new HashMap<>();
private static final Map<FlagsAndRunner, Path> downgradedPaths = new ConcurrentHashMap<>();

private static Path getDowngradedPath(FlagsAndRunner flags) {
String fName = original.getFileName().toString();
Expand All @@ -137,7 +138,7 @@ private static Path getDowngradedPath(FlagsAndRunner flags) {
return original.resolveSibling(withoutExt + "-downgrade-" + flags.readableSlug() + ext);
}

private static final Map<FlagsAndRunner, Path> shadedPaths = new HashMap<>();
private static final Map<FlagsAndRunner, Path> shadedPaths = new ConcurrentHashMap<>();

private static Path getShadedPath(FlagsAndRunner flags) {
String fName = original.getFileName().toString();
Expand All @@ -163,7 +164,7 @@ private static synchronized Path getDowngradedJar(FlagsAndRunner flags) {
});
}

private static final Map<FlagsAndRunner, Path> apiPaths = new HashMap<>();
private static final Map<FlagsAndRunner, Path> apiPaths = new ConcurrentHashMap<>();

private static synchronized Path getShadedJar(FlagsAndRunner flags) {
return apiPaths.computeIfAbsent(flags, e -> {
Expand Down

0 comments on commit 953b663

Please sign in to comment.