Skip to content
Permalink
Browse files
Blockers short models created to reduce GC; Full Test Ocurrence conve…
…rt removed (#141)
  • Loading branch information
dspavlov committed Jul 31, 2019
1 parent d574430 commit 8c1af8473a1d4367bc72f6f1797e36ef6d26309f
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 150 deletions.
@@ -67,6 +67,8 @@
import org.apache.ignite.tcbot.engine.pr.PrChainsProcessor;
import org.apache.ignite.tcbot.engine.ui.DsSuiteUi;
import org.apache.ignite.tcbot.engine.ui.DsTestFailureUi;
import org.apache.ignite.tcbot.engine.ui.ShortSuiteUi;
import org.apache.ignite.tcbot.engine.ui.ShortTestFailureUi;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
@@ -753,13 +755,13 @@ public CurrentVisaStatus currentVisaStatus(String srvCode, ITcBotUserCreds prov,
String tcBranch) {
CurrentVisaStatus status = new CurrentVisaStatus();

List<DsSuiteUi> suitesStatuses
List<ShortSuiteUi> suitesStatuses
= prChainsProcessor.getBlockersSuitesStatuses(buildTypeId, tcBranch, srvCode, prov, SyncMode.NONE, null);

if (suitesStatuses == null)
return status;

status.blockers = suitesStatuses.stream().mapToInt(DsSuiteUi::totalBlockers).sum();
status.blockers = suitesStatuses.stream().mapToInt(ShortSuiteUi::totalBlockers).sum();

return status;
}
@@ -806,15 +808,15 @@ public Visa notifyJira(
try {
String baseBranch = Strings.isNullOrEmpty(baseBranchForTc) ? prChainsProcessor.dfltBaseTcBranch(srvCodeOrAlias) : baseBranchForTc;

List<DsSuiteUi> suitesStatuses = prChainsProcessor.getBlockersSuitesStatuses(buildTypeId, build.branchName, srvCodeOrAlias, prov,
List<ShortSuiteUi> suitesStatuses = prChainsProcessor.getBlockersSuitesStatuses(buildTypeId, build.branchName, srvCodeOrAlias, prov,
SyncMode.RELOAD_QUEUED,
baseBranch);

if (suitesStatuses == null)
return new Visa("JIRA wasn't commented - no finished builds to analyze." +
" Check builds availabiliy for branch: " + build.branchName + "/" + baseBranch);

blockers = suitesStatuses.stream().mapToInt(DsSuiteUi::totalBlockers).sum();
blockers = suitesStatuses.stream().mapToInt(ShortSuiteUi::totalBlockers).sum();

String comment = generateJiraComment(suitesStatuses, build.webUrl, buildTypeId, tcIgnited, blockers, build.branchName, baseBranch);

@@ -843,7 +845,7 @@ public Visa notifyJira(
* @param baseBranch TC Base branch used for comment
* @return Comment, which should be sent to the JIRA ticket.
*/
private String generateJiraComment(List<DsSuiteUi> suites, String webUrl, String buildTypeId,
private String generateJiraComment(List<ShortSuiteUi> suites, String webUrl, String buildTypeId,
ITeamcityIgnited tcIgnited, int blockers, String branchName, String baseBranch) {
BuildTypeRefCompacted bt = tcIgnited.getBuildTypeRef(buildTypeId);

@@ -853,12 +855,12 @@ private String generateJiraComment(List<DsSuiteUi> suites, String webUrl, String

String baseBranchDisp = (Strings.isNullOrEmpty(baseBranch) || ITeamcity.DEFAULT.equals(baseBranch))
? "master" : baseBranch ;
for (DsSuiteUi suite : suites) {
for (ShortSuiteUi suite : suites) {
res.append("{color:#d04437}");

res.append(jiraEscText(suite.name)).append("{color}");

int totalBlockerTests = suite.testFailures.size();
int totalBlockerTests = suite.testFailures().size();
res.append(" [[tests ").append(totalBlockerTests);

if (suite.result != null && !suite.result.isEmpty())
@@ -868,7 +870,7 @@ private String generateJiraComment(List<DsSuiteUi> suites, String webUrl, String

int cnt = 0;

for (DsTestFailureUi failure : suite.testFailures) {
for (ShortTestFailureUi failure : suite.testFailures()) {
res.append("* ");

if (failure.suiteName != null && failure.testName != null)
@@ -30,6 +30,8 @@

import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.engine.pr.PrChainsProcessor;
import org.apache.ignite.tcbot.engine.ui.ShortSuiteUi;
import org.apache.ignite.tcbot.engine.ui.ShortTestFailureUi;
import org.apache.ignite.tcignited.SyncMode;
import org.apache.ignite.tcservice.ITeamcity;
import org.apache.ignite.tcservice.model.conf.BuildType;
@@ -117,23 +119,23 @@ public void testTestFailureWithoutStatReportedAsBlocker() {
initBuildChainAndMasterHistory(c, btId, branch);

PrChainsProcessor prcp = injector.getInstance(PrChainsProcessor.class);
final List<DsSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);
final List<ShortSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);

System.out.println(blockers);
assertNotNull(blockers);
assertFalse(blockers.isEmpty());

assertTrue(containsTestFailure(blockers, TEST_WITHOUT_HISTORY));

assertTrue(blockers.stream().anyMatch(s -> BUILD_APACHE_IGNITE.equals(s.suiteId)));
assertTrue(blockers.stream().anyMatch(s -> "CancelledBuild".equals(s.suiteId)));
assertTrue(blockers.stream().anyMatch(s -> BUILD_APACHE_IGNITE.equals(s.name)));
assertTrue(blockers.stream().anyMatch(s -> "CancelledBuild".equals(s.name)));

assertTrue(containsTestFailure(blockers, TEST_WITH_HISTORY_PASSING_IN_MASTER));

assertFalse(containsTestFailure(blockers, TEST_WITH_HISTORY_FAILING_IN_MASTER));
assertFalse(containsTestFailure(blockers, TEST_FLAKY_IN_MASTER));

Optional<DsTestFailureUi> testOpt = findBlockerTestFailure(blockers, TEST_WITH_HISTORY_PASSING_IN_MASTER);
Optional<? extends ShortTestFailureUi> testOpt = findBlockerTestFailure(blockers, TEST_WITH_HISTORY_PASSING_IN_MASTER);
assertTrue(testOpt.isPresent());

assertTrue(containsTestFailure(blockers, TEST_WAS_FIXED_IN_MASTER));
@@ -143,7 +145,7 @@ public void testTestFailureWithoutStatReportedAsBlocker() {
assertTrue(containsTestFailure(blockers, TEST_WITH_HISTORY_PASSING_IN_MASTER));
}

public boolean containsTestFailure(List<DsSuiteUi> blockers, String name) {
public boolean containsTestFailure(List<ShortSuiteUi> blockers, String name) {
return blockers.stream().anyMatch(containsTestFail(name));
}

@@ -163,30 +165,28 @@ public void testFlakyDetector() {
initHistory(c);

PrChainsProcessor prcp = injector.getInstance(PrChainsProcessor.class);
final List<DsSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);
final List<ShortSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);

System.out.println(blockers);

Optional<DsTestFailureUi> rareNotFlaky = findBlockerTestFailure(blockers, TEST_RARE_FAILED_WITH_CHANGES);
Optional<? extends ShortTestFailureUi> rareNotFlaky = findBlockerTestFailure(blockers, TEST_RARE_FAILED_WITH_CHANGES);
assertTrue(rareNotFlaky.isPresent());

assertNull(rareNotFlaky.get().histBaseBranch.flakyComments);

assertFalse(findBlockerTestFailure(blockers, TEST_RARE_FAILED_WITHOUT_CHANGES).isPresent());
}

public Optional<DsTestFailureUi> findBlockerTestFailure(List<DsSuiteUi> blockers, String name) {
Optional<DsSuiteUi> suiteOpt = blockers.stream().filter(containsTestFail(name)).findAny();
public Optional<? extends ShortTestFailureUi> findBlockerTestFailure(List<ShortSuiteUi> blockers, String name) {
Optional<ShortSuiteUi> suiteOpt = blockers.stream().filter(containsTestFail(name)).findAny();

return suiteOpt.flatMap(suite -> suite.testFailures.stream().filter(tf -> name.equals(tf.name)).findAny());
return suiteOpt.flatMap(suite -> suite.testFailures().stream().filter(tf -> name.equals(tf.name)).findAny());
}

/**
* @param name Test failure Name to find.
*/
@NotNull
private Predicate<DsSuiteUi> containsTestFail(String name) {
return s -> s.testFailures.stream().anyMatch(testFailure -> {
private Predicate<ShortSuiteUi> containsTestFail(String name) {
return s -> s.testFailures().stream().anyMatch(testFailure -> {
return name.equals(testFailure.name);
});
}
@@ -440,11 +440,11 @@ public void testTemplateDetectionInBranch() {

PrChainsProcessor prcp = injector.getInstance(PrChainsProcessor.class);

final List<DsSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);
final List<ShortSuiteUi> blockers = prcp.getBlockersSuitesStatuses(btId, branch, SRV_ID, mock(ITcBotUserCreds.class), SyncMode.RELOAD_QUEUED, null);

System.out.println(blockers);

Optional<DsTestFailureUi> testBecameFailed = findBlockerTestFailure(blockers, TEST_BECAME_FAILED_IN_BRANCH);
Optional<? extends ShortTestFailureUi> testBecameFailed = findBlockerTestFailure(blockers, TEST_BECAME_FAILED_IN_BRANCH);
assertTrue(testBecameFailed.isPresent());
}
}
@@ -177,13 +177,6 @@ public List<ChangeCompacted> getChanges() {
return Collections.unmodifiableList(changes);
}

public List<TestOccurrenceFull> getTests() {
if (isComposite())
return Collections.emptyList();

return buildCompacted.getTestOcurrences(compactor).getTests();
}

@Nonnull Stream<? extends Future<?>> getFutures() {
return logCheckResFut == null ? Stream.empty() : Stream.of((Future<?>)logCheckResFut);
}
@@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.TestCompacted;
import org.apache.ignite.tcbot.common.TcBotConst;
@@ -91,14 +92,14 @@ public long getAvgDurationMs() {
return avgDuration;
}


public Iterable<TestOccurrenceFull> getOccurrences() {
return occurrences.stream()
.map(testCompacted -> testCompacted.toTestOccurrence(compactor, 0))
.collect(Collectors.toList());
/**
*
*/
public Stream<TestCompacted> getInvocationsStream() {
return occurrences.stream();
}

/**
/**
* @param baseBranchStat Base branch statistics.
* @return non null comment in case test failure is a blocker for merge into base branch.
*/
@@ -42,9 +42,9 @@
import org.apache.ignite.tcbot.engine.conf.ITrackedBranch;
import org.apache.ignite.tcbot.engine.conf.ITrackedChain;
import org.apache.ignite.tcbot.engine.ui.DsChainUi;
import org.apache.ignite.tcbot.engine.ui.DsSuiteUi;
import org.apache.ignite.tcbot.engine.ui.DsSummaryUi;
import org.apache.ignite.tcbot.engine.ui.DsTestFailureUi;
import org.apache.ignite.tcbot.engine.ui.ShortSuiteUi;
import org.apache.ignite.tcbot.engine.ui.ShortTestFailureUi;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
@@ -254,7 +254,7 @@ public void initJiraAndGitInfo(DsChainUi chainStatus,
* @return List of suites with possible blockers.
*/
@Nullable
public List<DsSuiteUi> getBlockersSuitesStatuses(
public List<ShortSuiteUi> getBlockersSuitesStatuses(
String buildTypeId,
String branchForTc,
String srvCodeOrAlias,
@@ -290,7 +290,7 @@ public List<DsSuiteUi> getBlockersSuitesStatuses(
* @param baseBranch
*/
//todo may avoid creation of UI model for simple comment.
private List<DsSuiteUi> findBlockerFailures(FullChainRunCtx fullChainRunCtx,
private List<ShortSuiteUi> findBlockerFailures(FullChainRunCtx fullChainRunCtx,
ITeamcityIgnited tcIgnited,
String baseBranch) {
String normalizedBaseBranch = RunHistSync.normalizeBranch(baseBranch);
@@ -306,32 +306,20 @@ private List<DsSuiteUi> findBlockerFailures(FullChainRunCtx fullChainRunCtx,

String suiteComment = ctx.getPossibleBlockerComment(compactor, statInBaseBranch, tcIgnited.config());

List<DsTestFailureUi> failures = ctx.getFilteredTests(test -> test.includeIntoReport(tcIgnited, baseBranchId))
List<ShortTestFailureUi> failures = ctx.getFilteredTests(test -> test.includeIntoReport(tcIgnited, baseBranchId))
.stream()
.map(occurrence -> {
IRunHistory stat = occurrence.history(tcIgnited, baseBranchId);
String testBlockerComment = occurrence.getPossibleBlockerComment(stat);
ShortTestFailureUi tst = new ShortTestFailureUi().initFrom(occurrence, tcIgnited, baseBranchId);

if (!Strings.isNullOrEmpty(testBlockerComment)) {
final DsTestFailureUi failure = new DsTestFailureUi();

failure.initFromOccurrence(occurrence, tcIgnited, ctx.projectId(), ctx.branchName(), baseBranch, baseBranchId);

return failure;
}
return null;
return tst.isPossibleBlocker() ? tst : null;
}).filter(Objects::nonNull).collect(Collectors.toList());


// test failure based blockers and/or blocker found by suite results
if (!failures.isEmpty() || !Strings.isNullOrEmpty(suiteComment)) {

DsSuiteUi suiteUi = new DsSuiteUi();
suiteUi.testFailures = failures;

suiteUi.initFromContext(tcIgnited, ctx, baseBranch, compactor, false, false, -1);

return suiteUi;
return new ShortSuiteUi()
.testShortFailures(failures)
.initFrom(ctx, tcIgnited, compactor, statInBaseBranch);
}

return null;

0 comments on commit 8c1af84

Please sign in to comment.