Search in sources :

Example 1 with GitExecTimeout

use of jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method should_not_retry_fetch_mirror_for_exec_timeout.

@Test(enabled = false)
@TestFor(issues = "TW-56415")
public void should_not_retry_fetch_mirror_for_exec_timeout() throws Exception {
    MockFS fs = new MockFS();
    LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(fs).build();
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    // run build to prepare mirror
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(true), false);
    // update remote repo: add personal branch
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2.personal");
    copyRepository(updatedRepo, remoteRepo);
    // make first two fetches in local mirror to fail:
    loggingFactory.addCallback(FetchCommand.class.getName() + ".call", new GitCommandProxyCallback() {

        volatile boolean thrown = false;

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (!thrown) {
                thrown = true;
                throw new GitExecTimeout();
            }
            fail("Should not try to fetch again");
            return null;
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // try to fetch unknown branch, first fetch fails with exec timeout, repo would be remapped
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    AgentRunningBuild build = runningBuild().useLocalMirrors(true).sharedConfigParams("teamcity.git.fetchMirrorRetryTimeouts", "0,0").withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
    try {
        myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
        fail("GitExecTimeout exception expected");
    } catch (GitExecTimeout ignored) {
    }
    // try again, should succeed without remapping, means previous code has not changed mirror directory
    loggingFactory.addCallback(FetchCommand.class.getName() + ".call", (method, args) -> null);
    myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // repository was not remapped to another dir
    then(mirrorAfterBuild).isEqualTo(mirror);
}
Also used : AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) GitExecTimeout(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 2 with GitExecTimeout

use of jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout in project teamcity-git by JetBrains.

the class CommandUtil method isRecoverable.

public static boolean isRecoverable(@NotNull Exception e, AuthSettings authSettings, int attempt, int maxAttempts) {
    boolean attemptsLeft = attempt < maxAttempts;
    if (e instanceof ProcessTimeoutException || e instanceof GitExecTimeout)
        return attemptsLeft;
    if (!(e instanceof VcsException))
        return false;
    final VcsException ve = (VcsException) e;
    if (isTimeoutError(ve) || isConnectionRefused(ve) || isConnectionReset(ve))
        return attemptsLeft;
    if (isCanceledError(ve))
        return false;
    if (e instanceof GitIndexCorruptedException)
        return false;
    if (authSettings.doesTokenNeedRefresh() && attempt == 1)
        return true;
    return attemptsLeft && !isRemoteAccessError(ve);
}
Also used : GitExecTimeout(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout) GitIndexCorruptedException(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitIndexCorruptedException) VcsException(jetbrains.buildServer.vcs.VcsException) ProcessTimeoutException(jetbrains.buildServer.ProcessTimeoutException)

Example 3 with GitExecTimeout

use of jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method do_not_delete_mirror_on_timeout.

public void do_not_delete_mirror_on_timeout() throws Exception {
    MockFS fs = new MockFS();
    myVcsSupport = myBuilder.setFS(fs).build();
    String unreachableRepository = "git://some.org/unreachable.git";
    File mirror = myBuilder.getMirrorManager().getMirrorDir(unreachableRepository);
    // if plugin will remove mirror it will fail and try to remap
    fs.makeDeleteFail(mirror);
    myRoot = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(unreachableRepository).build();
    try {
        String revision = "abababababababababababababababababababab";
        AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.git.idle.timeout.seconds", "1").build();
        myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, revision, myCheckoutDir, build, false);
        fail("update on unreachable repository should fail");
    } catch (VcsException e) {
        if (e instanceof GitExecTimeout) {
            File mirrorAfterFailure = myBuilder.getMirrorManager().getMirrorDir(unreachableRepository);
            then(mirrorAfterFailure).overridingErrorMessage("Mirror changed after error " + e.toString()).isEqualTo(// failure should not cause delete or remap
            mirror);
        } else {
            // on some platforms fetch from unknown host doesn't result in timeout error
            throw new SkipException("Not a timeout error: " + e.toString());
        }
    }
}
Also used : GitExecTimeout(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout) VcsException(jetbrains.buildServer.vcs.VcsException) SkipException(org.testng.SkipException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Aggregations

GitExecTimeout (jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout)3 VcsException (jetbrains.buildServer.vcs.VcsException)3 File (java.io.File)2 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)2 Method (java.lang.reflect.Method)1 ProcessTimeoutException (jetbrains.buildServer.ProcessTimeoutException)1 GitIndexCorruptedException (jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitIndexCorruptedException)1 TestFor (jetbrains.buildServer.util.TestFor)1 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)1 SkipException (org.testng.SkipException)1 AfterMethod (org.testng.annotations.AfterMethod)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1