Skip to content

Commit

Permalink
Make data setup in ParallelBuildChainTest explicit per test case #659
Browse files Browse the repository at this point in the history
Define number of projects and number of allowed parallel builds per test
case instead of for the whole test class to ensure that test cases can
use different values for different purposes. Improve consistency and
readability by using explicitly defined and equal values for number of
projects and number of parallel builds.

Contributes to
#659.
  • Loading branch information
HeikoKlare committed Sep 12, 2023
1 parent 6797ba2 commit 418fcfc
Showing 1 changed file with 70 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
import org.junit.Test;

public class ParallelBuildChainTest extends AbstractBuilderTest {
private static final int NUMBER_OF_PROJECTS_TO_CREATE_AT_ONCE = 3;

private static final int MAXIMUM_NUMBER_OF_CONCURRENT_BUILDS = 3;

private static final int TIMEOUT_IN_MILLIS = 20_000;

private static enum BuildDurationType {
Expand Down Expand Up @@ -103,95 +99,114 @@ public ParallelBuildChainTest(String name) {
@Override
protected void setUp() throws Exception {
super.setUp();
setWorkspaceMaxNumberOfConcurrentBuilds();
setAutoBuilding(false);
}

@Override
protected void tearDown() throws Exception {
// Cleanup workspace first to ensure that auto-build is not started on projects
cleanup();
super.tearDown();
TimerBuilder.abortCurrentBuilds();
}

private void setWorkspaceMaxNumberOfConcurrentBuilds() throws CoreException {
private void setWorkspaceMaxNumberOfConcurrentBuilds(int maximumNumberOfConcurrentBuilds) throws CoreException {
IWorkspaceDescription description = getWorkspace().getDescription();
description.setMaxConcurrentBuilds(MAXIMUM_NUMBER_OF_CONCURRENT_BUILDS);
description.setMaxConcurrentBuilds(maximumNumberOfConcurrentBuilds);
getWorkspace().setDescription(description);
}

@Test
public void testIndividualProjectBuilds_NoConflictRule() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING, RuleType.NO_CONFLICT);
executeIndividualFullProjectBuilds(() -> {
int numberOfParallelBuilds = 3;
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.LONG_RUNNING,
RuleType.NO_CONFLICT);
executeIndividualFullProjectBuilds(numberOfParallelBuilds, () -> {
assertBuildsToStart(getAllProjects());
assertMinimumNumberOfSimultaneousBuilds(longRunningProjects.size());
});
}

@Test
public void testIndividualProjectBuilds_ProjectRelaxedRule() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.CURRENT_PROJECT_RELAXED);
var longRunningProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING,
int numberOfParallelBuilds = 3;
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE,
RuleType.CURRENT_PROJECT_RELAXED);
executeIndividualFullProjectBuilds(() -> {
var longRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.LONG_RUNNING,
RuleType.CURRENT_PROJECT_RELAXED);
executeIndividualFullProjectBuilds(numberOfParallelBuilds, () -> {
assertBuildsToStart(getAllProjects());
assertMinimumNumberOfSimultaneousBuilds(longRunningProjects.size());
});
}

@Test
public void testWorkspaceBuild_NoConflictRule() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningBuildProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningBuildProjects = createMultipleTestProjects(numberOfParallelBuilds,
BuildDurationType.LONG_RUNNING, RuleType.NO_CONFLICT);
executeIncrementalWorkspaceBuild(() -> {
assertBuildsToStart(longRunningBuildProjects);
assertMinimumNumberOfSimultaneousBuilds(longRunningBuildProjects.size());
assertMaximumNumberOfWorkspaceBuilds();
assertMaximumNumberOfConcurrentWorkspaceBuilds();
});
}

@Test
public void testWorkspaceBuild_NoConflictRule_WithBuildConfigurations() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningBuildProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var longRunningBuildProjects = createMultipleTestProjects(numberOfParallelBuilds,
BuildDurationType.LONG_RUNNING, RuleType.NO_CONFLICT);
IBuildConfiguration[] buildConfigurations = getBuildConfigurations(getAllProjects());
executeIncrementalWorkspaceBuild(buildConfigurations, () -> {
assertBuildsToStart(longRunningBuildProjects);
assertMinimumNumberOfSimultaneousBuilds(longRunningBuildProjects.size());
assertMaximumNumberOfWorkspaceBuilds();
assertMaximumNumberOfConcurrentWorkspaceBuilds();
});
}

@Test
public void testWorkspaceBuild_ProjectRule() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.CURRENT_PROJECT);
var longRunningProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING, RuleType.CURRENT_PROJECT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.CURRENT_PROJECT);
var longRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.LONG_RUNNING,
RuleType.CURRENT_PROJECT);
executeIncrementalWorkspaceBuild(() -> {
assertBuildsToStart(longRunningProjects);
assertMinimumNumberOfSimultaneousBuilds(longRunningProjects.size());
assertMaximumNumberOfWorkspaceBuilds();
assertMaximumNumberOfConcurrentWorkspaceBuilds();
});
}

@Test
public void testWorkspaceBuild_ProjectRule_WithBuildConfigurations() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.CURRENT_PROJECT);
var longRunningBuildProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING,
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.CURRENT_PROJECT);
var longRunningBuildProjects = createMultipleTestProjects(numberOfParallelBuilds,
BuildDurationType.LONG_RUNNING,
RuleType.CURRENT_PROJECT);
IBuildConfiguration[] buildConfigurations = getBuildConfigurations(getAllProjects());
executeIncrementalWorkspaceBuild(buildConfigurations, () -> {
assertBuildsToStart(longRunningBuildProjects);
assertMinimumNumberOfSimultaneousBuilds(longRunningBuildProjects.size());
assertMaximumNumberOfWorkspaceBuilds();
assertMaximumNumberOfConcurrentWorkspaceBuilds();
});
}

@Test
public void testWorkspaceBuild_ConflictingRule() throws Exception {
int millisToWaitForUnexpectedParallelBuild = 3_000;
var longRunningProjects = createMultipleTestProjects(BuildDurationType.LONG_RUNNING, RuleType.WORKSPACE_ROOT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
var longRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.LONG_RUNNING,
RuleType.WORKSPACE_ROOT);
executeIncrementalWorkspaceBuild(() -> {
waitForCondition(() -> TimerBuilder.getStartedProjectBuilds().size() > 1,
millisToWaitForUnexpectedParallelBuild);
Expand All @@ -203,8 +218,11 @@ public void testWorkspaceBuild_ConflictingRule() throws Exception {
}

public void testWorkspaceBuild_DependentProjects() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(BuildDurationType.SHORT_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.SHORT_RUNNING,
RuleType.NO_CONFLICT);
var projectsToBuild = getAllProjects();
makeProjectsDependOnEachOther(projectsToBuild);
int minimumExecutionTimeInMillis = shortRunningProjects.size()
Expand All @@ -220,8 +238,12 @@ public void testWorkspaceBuild_DependentProjects() throws Exception {
}

public void testWorkspaceBuild_DependentProjects_ProjectSubset() throws Exception {
var immediateBuiltProjects = createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(BuildDurationType.SHORT_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
var immediateBuiltProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE,
RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.SHORT_RUNNING,
RuleType.NO_CONFLICT);
var projectsToBuild = List.of(immediateBuiltProjects.get(0),
immediateBuiltProjects.get(immediateBuiltProjects.size() - 1), shortRunningProjects.get(0),
shortRunningProjects.get(shortRunningProjects.size() - 1));
Expand All @@ -239,8 +261,11 @@ public void testWorkspaceBuild_DependentProjects_ProjectSubset() throws Exceptio
}

public void testWorkspaceBuild_DependentProjectBuildConfigurations() throws Exception {
createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(BuildDurationType.SHORT_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.SHORT_RUNNING,
RuleType.NO_CONFLICT);
var projectsToBuild = getAllProjects();
makeProjectBuildConfigurationsDependOnEachOther(projectsToBuild);
int minimumExecutionTimeInMillis = shortRunningProjects.size()
Expand All @@ -256,8 +281,12 @@ public void testWorkspaceBuild_DependentProjectBuildConfigurations() throws Exce
}

public void testWorkspaceBuild_DependentProjectBuildConfigurations_ProjectSubset() throws Exception {
var immediateBuiltProjects = createMultipleTestProjects(BuildDurationType.IMMEDIATE, RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(BuildDurationType.SHORT_RUNNING, RuleType.NO_CONFLICT);
int numberOfParallelBuilds = 3;
setWorkspaceMaxNumberOfConcurrentBuilds(numberOfParallelBuilds);
var immediateBuiltProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.IMMEDIATE,
RuleType.NO_CONFLICT);
var shortRunningProjects = createMultipleTestProjects(numberOfParallelBuilds, BuildDurationType.SHORT_RUNNING,
RuleType.NO_CONFLICT);
var projectsToBuild = List.of(immediateBuiltProjects.get(0),
immediateBuiltProjects.get(immediateBuiltProjects.size() - 1), shortRunningProjects.get(0),
shortRunningProjects.get(shortRunningProjects.size() - 1));
Expand Down Expand Up @@ -286,10 +315,11 @@ private static IBuildConfiguration[] getBuildConfigurations(List<IProject> proje
return buildConfigurations;
}

private List<IProject> createMultipleTestProjects(BuildDurationType buildDurationType, RuleType ruleType)
private List<IProject> createMultipleTestProjects(int numberOfProjects, BuildDurationType buildDurationType,
RuleType ruleType)
throws CoreException {
List<IProject> result = new ArrayList<>();
for (int projectNumber = 0; projectNumber < NUMBER_OF_PROJECTS_TO_CREATE_AT_ONCE; projectNumber++) {
for (int projectNumber = 0; projectNumber < numberOfProjects; projectNumber++) {
result.add(createTestProject(buildDurationType, ruleType));
}
return result;
Expand Down Expand Up @@ -383,11 +413,11 @@ protected IStatus run(IProgressMonitor monitor) {
}
}

private void executeIndividualFullProjectBuilds(Runnable executeWhileRunningBuild) throws Exception {
int maximumThreadsForJobGroup = 5;
private void executeIndividualFullProjectBuilds(int numberOfParallelBuilds, Runnable executeWhileRunningBuild)
throws Exception {
List<IProject> projects = getAllProjects();
TimerBuilder.setExpectedNumberOfBuilds(projects.size());
JobGroup jobGroup = new JobGroup("Build Group", maximumThreadsForJobGroup, projects.size());
JobGroup jobGroup = new JobGroup("Build Group", numberOfParallelBuilds, projects.size());
Map<IProject, TestBarrier2> waitForRunningJobBarriers = new HashMap<>();
for (IProject project : projects) {
waitForRunningJobBarriers.put(project, new TestBarrier2());
Expand Down Expand Up @@ -431,7 +461,7 @@ private void assertMaximumNumberOfSimultaneousBuilds(int maximumNumberOfSimulane
lessThanOrEqualTo(maximumNumberOfSimulaneousBuilds));
}

private void assertMaximumNumberOfWorkspaceBuilds() {
private void assertMaximumNumberOfConcurrentWorkspaceBuilds() {
assertThat("too many workspace builds have run in parallel",
TimerBuilder.getMaximumNumberOfSimultaneousBuilds(),
lessThanOrEqualTo(getWorkspace().getDescription().getMaxConcurrentBuilds()));
Expand Down

0 comments on commit 418fcfc

Please sign in to comment.