Skip to content

Commit

Permalink
Run tests sequentially.
Browse files Browse the repository at this point in the history
Add comment.
  • Loading branch information
khatchad committed Nov 9, 2023
1 parent 617041b commit 12a721e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -25,7 +26,7 @@
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
import org.python.pydev.ast.refactoring.TooManyMatchesException;
import org.python.pydev.ast.refactoring.TooManyMatchesException; /* FIXME: This exception sounds too low-level. */
import org.python.pydev.core.preferences.InterpreterGeneralPreferences;

import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
Expand Down Expand Up @@ -100,6 +101,8 @@ private static RefactoringStatus checkParameters(Function func) {

private boolean alwaysCheckPythonSideEffects;

private boolean processFunctionsInParallel = true;

public HybridizeFunctionRefactoringProcessor() {
// Force the use of typeshed. It's an experimental feature of PyDev.
InterpreterGeneralPreferences.FORCE_USE_TYPESHED = TRUE;
Expand All @@ -113,7 +116,13 @@ public HybridizeFunctionRefactoringProcessor(boolean alwaysCheckPythonSideEffect
this.alwaysCheckPythonSideEffects = alwaysCheckPythonSideEffects;
}

public HybridizeFunctionRefactoringProcessor(Set<FunctionDefinition> functionDefinitionSet) throws TooManyMatchesException {
public HybridizeFunctionRefactoringProcessor(boolean alwaysCheckPythonSideEffects, boolean processFunctionsInParallel) {
this(alwaysCheckPythonSideEffects);
this.processFunctionsInParallel = processFunctionsInParallel;
}

public HybridizeFunctionRefactoringProcessor(Set<FunctionDefinition> functionDefinitionSet)
throws TooManyMatchesException /* FIXME: This exception sounds too low-level. */ {
this();

// Convert the FunctionDefs to Functions.
Expand All @@ -130,11 +139,17 @@ public HybridizeFunctionRefactoringProcessor(Set<FunctionDefinition> functionDef
}

public HybridizeFunctionRefactoringProcessor(Set<FunctionDefinition> functionDefinitionSet, boolean alwaysCheckPythonSideEffects)
throws TooManyMatchesException {
throws TooManyMatchesException /* FIXME: This exception sounds too low-level. */ {
this(functionDefinitionSet);
this.alwaysCheckPythonSideEffects = alwaysCheckPythonSideEffects;
}

public HybridizeFunctionRefactoringProcessor(Set<FunctionDefinition> functionDefinitionSet, boolean alwaysCheckPythonSideEffects,
boolean processFunctionsInParallel) throws TooManyMatchesException /* FIXME: This exception sounds too low-level. */ {
this(functionDefinitionSet, alwaysCheckPythonSideEffects);
this.processFunctionsInParallel = processFunctionsInParallel;
}

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context)
throws CoreException, OperationCanceledException {
Expand Down Expand Up @@ -208,7 +223,7 @@ private RefactoringStatus checkFunctions(IProgressMonitor monitor) throws Operat
LOG.info("Checking " + projectFunctions.size() + " function" + (allFunctions.size() > 1 ? "s" : "") + ".");
subMonitor.beginTask(Messages.CheckingFunctions, allFunctions.size());

projectFunctions.parallelStream().forEach(func -> {
this.getStream(projectFunctions).forEach(func -> {
LOG.info("Checking function: " + func + ".");

// Find out if it's hybrid via the tf.function decorator.
Expand Down Expand Up @@ -257,6 +272,18 @@ private RefactoringStatus checkFunctions(IProgressMonitor monitor) throws Operat
return status;
}

/**
* Returns a {@link Stream} of {@link Function}s. Properties of the stream are dependent on the state of this
* {@link HybridizeFunctionRefactoringProcessor}.
*
* @param functions The {@link Set} of {@link Function}s from which to derive a {@link Stream}.
* @return A potentially parallel {@link Stream} of {@link Function}s.
*/
private Stream<Function> getStream(Set<Function> functions) {
Stream<Function> stream = functions.stream();
return this.getProcessFunctionsInParallel() ? stream.parallel() : stream;
}

private TensorTypeAnalysis computeTensorTypeAnalysis(EclipsePythonProjectTensorAnalysisEngine engine,
PythonSSAPropagationCallGraphBuilder builder) throws CancelException {
Map<IProject, TensorTypeAnalysis> projectToTensorTypeAnalysis = this.getProjectToTensorTypeAnalysis();
Expand Down Expand Up @@ -372,4 +399,13 @@ protected boolean getDumpCallGraph() {
public Map<IProject, TensorTypeAnalysis> getProjectToTensorTypeAnalysis() {
return projectToTensorTypeAnalysis;
}

/**
* True iff project functions should be processed in parallel. Otherwise, they are processed sequentially.
*
* @return True iff project functions should be processed in parallel.
*/
private boolean getProcessFunctionsInParallel() {
return this.processFunctionsInParallel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public int getInterpreterType() throws CoreException {
*/
private static final boolean ALWAYS_CHECK_PYTHON_SIDE_EFFECTS = true;

/**
* Whether we should run the function processing in parallel. Running in parallel makes the logs difficult to read and doesn't offer
* much in way of speedup since each test has only a few {@link Function}s.
*/
private static final boolean PROCESS_FUNCTIONS_IN_PARALLEL = false;

/**
* Add a module to the given {@link IPythonNature}.
*
Expand Down Expand Up @@ -556,7 +562,7 @@ private Set<Function> getFunctions(String fileNameWithoutExtension) throws Excep
.map(f -> new FunctionDefinition(f, fileNameWithoutExtension, inputTestFile, document, nature)).collect(Collectors.toSet());

HybridizeFunctionRefactoringProcessor processor = new HybridizeFunctionRefactoringProcessor(inputFunctionDefinitions,
ALWAYS_CHECK_PYTHON_SIDE_EFFECTS);
ALWAYS_CHECK_PYTHON_SIDE_EFFECTS, PROCESS_FUNCTIONS_IN_PARALLEL);

ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);

Expand Down

0 comments on commit 12a721e

Please sign in to comment.