Search in sources :

Example 1 with BuildBuilder

use of jetbrains.buildServer.buildTriggers.vcs.BuildBuilder in project teamcity-rest by JetBrains.

the class BuildPromotionFinderTest method testTimes.

@Test(dataProvider = "allBooleans")
public void testTimes(boolean timeAsSecondBoundary) {
    final MockTimeService time = new MockTimeService(Dates.now().getTime());
    myServer.setTimeService(time);
    // recreate finders to let time service sink in
    initFinders();
    if (timeAsSecondBoundary) {
        time.jumpTo(1000L - time.now() % 1000);
    } else if (time.now() % 1000 == 0) {
        time.jumpTo(10L);
    }
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    final SQueuedBuild queuedBuild10 = build().in(buildConf1).addToQueue();
    final SQueuedBuild queuedBuild20 = build().in(buildConf2).addToQueue();
    time.jumpTo(10);
    final SFinishedBuild build10 = myFixture.finishBuild(BuildBuilder.run(queuedBuild10, myFixture), false);
    time.jumpTo(10);
    final Date afterBuild10 = time.getNow();
    time.jumpTo(10);
    // ensuring next jump will be within the same second
    time.jumpTo(1000L - time.now() % 1000 + 100);
    final SFinishedBuild build20 = myFixture.finishBuild(BuildBuilder.run(queuedBuild20, myFixture), false);
    time.jumpTo(100L);
    final SFinishedBuild build23 = build().in(buildConf2).finish();
    time.jumpTo(10);
    final SFinishedBuild build25Deleted = build().in(buildConf2).failed().finish();
    final long build25DeletedId = build25Deleted.getBuildId();
    myFixture.getSingletonService(BuildHistory.class).removeEntry(build25Deleted);
    final BuildBuilder queuedBuild30 = build().in(buildConf2);
    time.jumpTo(10);
    final SFinishedBuild build30 = queuedBuild30.failedToStart().finish();
    time.jumpTo(10);
    final Date afterBuild30 = time.getNow();
    time.jumpTo(10);
    final SFinishedBuild build40 = build().in(buildConf1).finish();
    time.jumpTo(10);
    final SFinishedBuild build50Deleted = build().in(buildConf2).failed().finish();
    final long build50DeletedId = build50Deleted.getBuildId();
    myFixture.getSingletonService(BuildHistory.class).removeEntry(build50Deleted);
    final SFinishedBuild build60 = build().in(buildConf2).finish();
    time.jumpTo(10);
    final Date afterBuild60 = time.getNow();
    final SFinishedBuild build70 = build().in(buildConf1).finish();
    time.jumpTo(10);
    final SRunningBuild build80 = build().in(buildConf1).run();
    time.jumpTo(10);
    final SQueuedBuild queuedBuild110 = build().in(buildConf1).addToQueue();
    time.jumpTo(10);
    // preventing build from merging in the queue
    final SQueuedBuild queuedBuild120 = build().in(buildConf1).parameter("a", "x").addToQueue();
    time.jumpTo(10);
    // preventing build from merging in the queue
    final SQueuedBuild queuedBuild130 = build().in(buildConf1).parameter("a", "y").addToQueue();
    // noinspection ConstantConditions
    myFixture.getBuildQueue().moveTop(queuedBuild130.getItemId());
    checkBuilds("finishDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
    checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:after),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:before),state:any", getBuildPromotions(build10));
    checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + "),condition:equals),state:any", getBuildPromotions(build20));
    checkBuilds("finishDate:(build:(id:" + build20.getBuildId() + ")),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(build:(id:" + queuedBuild110.getItemId() + "))");
    if (build10.getFinishDate().getTime() % 1000 == 0) {
        // the comparison is strict "after", but the time in locator is with seconds precision, so times without ms part are special case
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
    } else {
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
        checkBuilds("finishDate:(date:" + Util.formatTime(build10.getFinishDate()) + ",condition:after,includeInitial:true),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20, build10));
    }
    checkBuilds("finishDate:(date:" + getTimeWithMs(build10.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(date:" + getTimeWithMs(build10.getFinishDate()) + ",condition:after),state:any,failedToStart:any", getBuildPromotions(build70, build60, build40, build30, build23, build20));
    checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + ",condition:after),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:after,includeInitial:true),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:before),state:any", getBuildPromotions(build10));
    checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + ",condition:equals),state:any", getBuildPromotions());
    checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + ",condition:equals),state:any", getBuildPromotions(build20));
    checkBuilds("finishDate:(date:" + Util.formatTime(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(date:" + getTimeWithMs(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSZ", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSSX", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23));
    checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", // new time parsing uses ms
    getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("finishDate:(date:" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.ENGLISH)).format(build20.getFinishDate()) + "),state:any", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "),condition:after)", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(build80, build70, build60, build40, build23, build20));
    checkBuilds("startDate:(build:(id:" + build10.getBuildId() + "))", getBuildPromotions(build70, build60, build40, build23, build20));
    if (build10.getStartDate().getTime() % 1000 == 0) {
        checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
        checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ",includeInitial:true)", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("startDate:(" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
    } else {
        checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("startDate:(date:" + Util.formatTime(build10.getStartDate()) + ",includeInitial:true)", getBuildPromotions(build70, build60, build40, build23, build20, build10));
        checkBuilds("startDate:(" + Util.formatTime(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20, build10));
    }
    checkBuilds("startDate:(date:" + getTimeWithMs(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("startDate:(" + getTimeWithMs(build10.getStartDate()) + ")", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("queuedDate:(build:(id:" + build10.getBuildId() + "),condition:after)", getBuildPromotions(build70, build60, build40, build23, build20));
    checkBuilds("queuedDate:(build:(id:" + build10.getBuildId() + "),condition:after),state:any", getBuildPromotions(queuedBuild130, queuedBuild110, queuedBuild120, build80, build70, build60, build40, build23, build20));
    checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40, build23, build20, build10));
    // set time to afterBuild30 + 10 minutes
    time.jumpTo(afterBuild30.getTime() + 10 * 60 * 1000 - time.getNow().getTime());
    checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40));
    time.jumpTo(9);
    checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60, build40));
    time.jumpTo(1);
    checkBuilds("startDate:(-10m),state:any", getBuildPromotions(build80, build70, build60));
    time.jumpTo(60 * 10);
    checkBuilds("startDate:(-10m),state:any");
    checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:-11s),state:any", getBuildPromotions(build80, build70, build60, build40));
    checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:-10s),state:any", getBuildPromotions(build80, build70, build60));
    checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:+9s),state:any", getBuildPromotions(build80, build70));
    checkBuilds("startDate:(build:(id:" + build60.getBuildId() + "),shift:+10s),state:any", getBuildPromotions(build80));
    checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-11s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+11s),state:any", getBuildPromotions(build70, build60, build40));
    checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-9s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+9s),state:any", getBuildPromotions(build60));
    checkBuilds("startDate:(condition:after,build:(id:" + build60.getBuildId() + ")" + ",shift:-10s),startDate:(condition:before,build:(id:" + build60.getBuildId() + "),shift:+10s),state:any", getBuildPromotions(build60));
    checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(xxx)");
    checkExceptionOnBuildsSearch(LocatorProcessException.class, "finishDate:(time:20150101T000000+0000,build:(id:3))");
    checkExceptionOnBuildsSearch(BadRequestException.class, "finishDate:(time:20150101T000000+0000,condition:xxx)");
}
Also used : MockTimeService(jetbrains.buildServer.MockTimeService) SimpleDateFormat(java.text.SimpleDateFormat) BuildBuilder(jetbrains.buildServer.buildTriggers.vcs.BuildBuilder) Test(org.testng.annotations.Test)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 MockTimeService (jetbrains.buildServer.MockTimeService)1 BuildBuilder (jetbrains.buildServer.buildTriggers.vcs.BuildBuilder)1 Test (org.testng.annotations.Test)1