Skip to content
Permalink
Browse files
Merge pull request #40 from jenkinsci/network-JENKINS-50597
[JENKINS-50597] Network behavior tuning II
  • Loading branch information
carlossg committed May 31, 2018
2 parents b09776a + 00ae5ec commit bb65de81dfd57fff12f5c8be30d19cfd11763742
@@ -55,6 +55,7 @@
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.google.common.base.Predicate;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.FilePath;
@@ -351,13 +352,17 @@ public Void invoke(File f, VirtualChannel channel) throws IOException, Interrupt
private static void uploadFile(Path f, URL url, final TaskListener listener) throws IOException {
String urlSafe = url.toString().replaceFirst("[?].+$", "?…");
try {
Predicate<Throwable> nonfatal = x -> x instanceof IOException && (!(x instanceof HttpResponseException) || ((HttpResponseException) x).getStatusCode() >= 500);
RetryerBuilder.<Void>newBuilder().
retryIfException(x -> x instanceof IOException && (!(x instanceof HttpResponseException) || ((HttpResponseException) x).getStatusCode() >= 500)).
retryIfException(nonfatal).
withRetryListener(new RetryListener() {
@Override
public <Void> void onRetry(Attempt<Void> attempt) {
if (attempt.hasException()) {
listener.getLogger().println("Retrying upload after: " + attempt.getExceptionCause());
Throwable t = attempt.getExceptionCause();
if (nonfatal.apply(t)) {
listener.getLogger().println("Retrying upload after: " + t);
}
}
}
}).
@@ -71,10 +71,11 @@ public void configureManager() throws Exception {
public void unrecoverableExceptionArchiving() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
r.createSlave("remote", null, null);
MockBlobStore.failIn(BlobStoreProvider.HttpMethod.PUT, "p/1/artifacts/f", 400);
MockBlobStore.failIn(BlobStoreProvider.HttpMethod.PUT, "p/1/artifacts/f", 403);
p.setDefinition(new CpsFlowDefinition("node('remote') {writeFile file: 'f', text: '.'; archiveArtifacts 'f'}", true));
WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
r.assertLogContains("/container/p/1/artifacts/f?…, response: 400 simulated 400 failure, body: Detailed explanation of 400.", b);
r.assertLogContains("/container/p/1/artifacts/f?…, response: 403 simulated 403 failure, body: Detailed explanation of 403.", b);
r.assertLogNotContains("Retrying upload", b);
}

@Test
@@ -85,6 +86,7 @@ public void recoverableExceptionArchiving() throws Exception {
p.setDefinition(new CpsFlowDefinition("node('remote') {writeFile file: 'f', text: '.'; archiveArtifacts 'f'}", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
r.assertLogContains("/container/p/1/artifacts/f?…, response: 500 simulated 500 failure, body: Detailed explanation of 500.", b);
r.assertLogContains("Retrying upload", b);
}

@Test
@@ -95,6 +97,7 @@ public void networkExceptionArchiving() throws Exception {
p.setDefinition(new CpsFlowDefinition("node('remote') {writeFile file: 'f', text: '.'; archiveArtifacts 'f'}", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
// currently prints a ‘java.net.SocketException: Connection reset’ but not sure if we really care
r.assertLogContains("Retrying upload", b);
}

}

0 comments on commit bb65de8

Please sign in to comment.