Skip to content

Commit

Permalink
add persistence every 100 failures in case of OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianHuc committed Oct 11, 2024
1 parent 58e48bc commit adf60bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -128,8 +129,20 @@ public static Map<String, Set<String>> extractConstraints(String message) {
}

@Synchronized
public static CompletableFuture<Void> writeToJsonFile() {
return writeToJsonFile(JSON_OUTPUT_FILENAME);
public static void writeToJsonFile(int count) {
try {
String directory = setFileDirectory();
log.info("Reference test will be written to file {}\\{}", directory, JSON_OUTPUT_FILENAME);
writeToJsonFile(JSON_OUTPUT_FILENAME+"_"+count);
log.info("Reference test results written to file {}", JSON_OUTPUT_FILENAME);
log.info(
"Path exists: {}, file exist: {}",
Paths.get(directory).toFile().exists(),
Paths.get(directory).resolve(JSON_OUTPUT_FILENAME).toFile().exists());
} catch (Exception e) {
log.error("Error while writing results");
throw new RuntimeException("Error while writing results", e);
}
}

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ public class ReferenceTestOutcomeWriter implements LauncherSessionListener {

@Override
public void launcherSessionClosed(LauncherSession session) {
try {
String directory = setFileDirectory();
log.info("Reference test will be written to file {}\\{}", directory, JSON_OUTPUT_FILENAME);
writeToJsonFile().get();
log.info("Reference test results written to file {}", JSON_OUTPUT_FILENAME);
log.info(
"Path exists: {}, file exist: {}",
Paths.get(directory).toFile().exists(),
Paths.get(directory).resolve(JSON_OUTPUT_FILENAME).toFile().exists());
} catch (Exception e) {
log.error("Error while writing results");
throw new RuntimeException("Error while writing results", e);
}
writeToJsonFile(-1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
*/
package net.consensys.linea;

import static net.consensys.linea.ReferenceTestOutcomeRecorderTool.writeToJsonFile;
import static net.consensys.linea.TestState.*;
import static net.consensys.linea.testing.ExecutionEnvironment.CORSET_VALIDATION_RESULT;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.opentest4j.AssertionFailedError;
Expand All @@ -33,13 +34,19 @@ public class ReferenceTestWatcher implements TestWatcher {
private static final String ASSERTION_FAILED = "ASSERTION_FAILED";
private static final String UNCATEGORIZED_EXCEPTION = "UNCATEGORIZED_EXCEPTION";

private static volatile AtomicInteger counter = new AtomicInteger(0);
@Override
public void testFailed(ExtensionContext context, Throwable cause) {
String testName = context.getDisplayName().split(": ")[1];
log.info("Adding failure for {}", testName);
Map<String, Set<String>> logEventMessages = getLogEventMessages(cause);
ReferenceTestOutcomeRecorderTool.mapAndStoreTestResult(testName, FAILED, logEventMessages);
log.info("Failure added for {}", testName);
int count = counter.incrementAndGet();
if(count%100 == 0){
log.info("intermediary persistence after {} failures", count);
writeToJsonFile(count);
}
}

private static Map<String, Set<String>> getLogEventMessages(Throwable cause) {
Expand Down

0 comments on commit adf60bc

Please sign in to comment.