Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.simple.SimpleConfig;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

@ResourceLock(value = "metrics") // Mutual exclusion to prevent flaky tests.
// We also want to ensure that tests of the same suite do not update the registry concurrently
@Execution(ExecutionMode.SAME_THREAD)
public abstract class AbstractMeterTest {

@BeforeEach // To guard against nasty tests which do not do this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ public static <Solution_> SolverConfig buildSolverConfig(Class<Solution_> soluti
new TerminationConfig().withStepCountLimit(TERMINATION_STEP_COUNT_LIMIT)));
}

public static <Solution_> Solution_ solve(SolverConfig solverConfig, Solution_ problem) {
public static synchronized <Solution_> Solution_ solve(SolverConfig solverConfig, Solution_ problem) {
return solve(solverConfig, problem, true);
}

public static <Solution_> Solution_ solve(SolverConfig solverConfig, Solution_ problem, boolean bestSolutionEventExists) {
/**
* We need to synchronize the solving process because there are some shared resources, such as the Meter registry,
* which could be updated concurrently.
*/
public static synchronized <Solution_> Solution_ solve(SolverConfig solverConfig, Solution_ problem,
Comment thread
zepfred marked this conversation as resolved.
boolean bestSolutionEventExists) {
SolverFactory<Solution_> solverFactory = SolverFactory.create(solverConfig);
var solver = solverFactory.buildSolver();
var eventBestSolutionRef = new AtomicReference<Solution_>();
Expand Down
Loading