in tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/chain/BuildChainProcessor.java [154:248]
public FullChainRunCtx loadFullChainContext(
ITeamcityIgnited tcIgn,
Collection<Integer> entryPoints,
LatestRebuildMode includeLatestRebuild,
ProcessLogsMode procLog,
boolean includeScheduledInfo,
@Nullable String failRateBranch,
SyncMode mode,
@Nullable SortOption sortOption,
@Nullable Map<Integer, Integer> requireParamVal) {
if (entryPoints.isEmpty())
return new FullChainRunCtx(Build.createFakeStub());
Integer failRateBranchId = compactor.getStringIdIfPresent(BranchEquivalence.normalizeBranch(failRateBranch));
Map<Integer, Future<FatBuildCompacted>> builds = loadAllBuildsInChains(entryPoints, mode, tcIgn);
Map<String, List<Future<FatBuildCompacted>>> freshRebuilds = new ConcurrentHashMap<>();
groupByBuildType(builds).forEach(
(k, buildsForBt) -> {
List<Future<FatBuildCompacted>> futures = replaceWithRecent(buildsForBt,
entryPoints.size(),
includeLatestRebuild,
builds,
mode,
tcIgn,
requireParamVal);
freshRebuilds.put(k, futures);
}
);
List<MultBuildRunCtx> contexts = new ArrayList<>(freshRebuilds.size());
freshRebuilds.forEach((bt, listBuilds) -> {
List<FatBuildCompacted> buildsForSuite = FutureUtil.getResults(listBuilds)
.filter(buildCompacted -> !buildCompacted.isFakeStub())
.collect(Collectors.toList());
if (buildsForSuite.isEmpty())
return;
BuildRef ref = buildsForSuite.iterator().next().toBuildRef(compactor);
final MultBuildRunCtx ctx = new MultBuildRunCtx(ref, compactor);
buildsForSuite.forEach(buildCompacted -> ctx.addBuild(loadChanges(buildCompacted, tcIgn)));
//ask for history for the suite in parallel
tcUpdatePool.getService().submit(() -> {
ctx.history(tcIgn, failRateBranchId, null);
});
analyzeTests(ctx, tcIgn, procLog);
fillBuildCounts(ctx, tcIgn, includeScheduledInfo);
contexts.add(ctx);
});
Integer someEntryPnt = entryPoints.iterator().next();
Future<FatBuildCompacted> build = getOrLoadBuild(someEntryPnt, mode, builds, tcIgn);
FullChainRunCtx fullChainRunCtx = new FullChainRunCtx(FutureUtil.getResult(build).toBuild(compactor));
Function<MultBuildRunCtx, Double> function = null;
if (sortOption == null || sortOption == SortOption.FailureRate) {
function = ctx -> {
IRunHistory runStat = ctx.history(tcIgn, failRateBranchId, null);
if (runStat == null)
return 0d;
//some hack to bring timed out suites to top
return runStat.getCriticalFailRate() * 3.14d + runStat.getFailRate();
};
}
else if (sortOption == SortOption.SuiteDuration) {
function = ctx -> {
Long duration = ctx.buildDuration();
return duration == null ? 0 : (double)duration;
};
}
if (function != null)
contexts.sort(Comparator.comparing(function).reversed());
fullChainRunCtx.addAllSuites(contexts);
return fullChainRunCtx;
}