From f9d962167bf88993d8c68aeab510e0a9c4e54298 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 21 Nov 2023 15:42:12 -0800 Subject: [PATCH] Cleanup test and do not run trace logging on slow tests --- pom.xml | 16 ----------- .../java/org/kohsuke/github/GitHubClient.java | 2 +- .../kohsuke/github/RequesterRetryTest.java | 27 ++++++++----------- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index a7bf493c16..4eef899b70 100644 --- a/pom.xml +++ b/pom.xml @@ -732,22 +732,6 @@ src/test/resources/slow-or-flaky-tests.txt - - slow-or-flaky-test-tracing - integration-test - - test - - - ${project.basedir}/target/github-api-${project.version}.jar - 2 - src/test/resources/slow-or-flaky-tests.txt - - - src/test/resources/test-trace-logging.properties - - - jwt0.11.x-test diff --git a/src/main/java/org/kohsuke/github/GitHubClient.java b/src/main/java/org/kohsuke/github/GitHubClient.java index 90708a9075..6f616b6512 100644 --- a/src/main/java/org/kohsuke/github/GitHubClient.java +++ b/src/main/java/org/kohsuke/github/GitHubClient.java @@ -689,8 +689,8 @@ private static void logRetryConnectionError(IOException e, URL url, int retries) () -> String.format( "(%s) %s while connecting to %s: '%s'. Sleeping %d milliseconds before retrying (%d retries remaining)", sendRequestTraceId.get(), - url.toString(), e.getClass().toString(), + url.toString(), e.getMessage(), sleepTime, retries)); diff --git a/src/test/java/org/kohsuke/github/RequesterRetryTest.java b/src/test/java/org/kohsuke/github/RequesterRetryTest.java index 4046608d83..411ad18267 100644 --- a/src/test/java/org/kohsuke/github/RequesterRetryTest.java +++ b/src/test/java/org/kohsuke/github/RequesterRetryTest.java @@ -178,8 +178,8 @@ public void testSocketConnectionAndRetry() throws Exception { } String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(true)); - assertThat(capturedLog.contains("will try 1 more time"), is(true)); + assertThat(capturedLog, containsString("(2 retries remaining)")); + assertThat(capturedLog, containsString("(1 retries remaining)")); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6)); } @@ -216,8 +216,8 @@ public void testSocketConnectionAndRetry_StatusCode() throws Exception { } String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(true)); - assertThat(capturedLog.contains("will try 1 more time"), is(true)); + assertThat(capturedLog, containsString("(2 retries remaining)")); + assertThat(capturedLog, containsString("(1 retries remaining)")); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6)); } @@ -275,8 +275,8 @@ public void testSocketConnectionAndRetry_Success() throws Exception { GHBranch branch = repo.getBranch("test/timeout"); assertThat(branch, notNullValue()); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(true)); - assertThat(capturedLog.contains("will try 1 more time"), is(true)); + assertThat(capturedLog, containsString("(2 retries remaining)")); + assertThat(capturedLog, containsString("(1 retries remaining)")); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6)); } @@ -307,8 +307,7 @@ public void testResponseCodeFailureExceptions() throws Exception { assertThat(e.getCause(), instanceOf(IOException.class)); assertThat(e.getCause().getMessage(), is("Custom")); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(false)); - assertThat(capturedLog.contains("will try 1 more time"), is(false)); + assertThat(capturedLog, not(containsString("retries remaining"))); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount)); } @@ -328,8 +327,7 @@ public void testResponseCodeFailureExceptions() throws Exception { assertThat(e, instanceOf(FileNotFoundException.class)); assertThat(e.getMessage(), is("Custom")); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(false)); - assertThat(capturedLog.contains("will try 1 more time"), is(false)); + assertThat(capturedLog, not(containsString("retries remaining"))); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount)); } } @@ -360,8 +358,7 @@ public void testInputStreamFailureExceptions() throws Exception { assertThat(e.getCause(), instanceOf(IOException.class)); assertThat(e.getCause().getMessage(), is("Custom")); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(false)); - assertThat(capturedLog.contains("will try 1 more time"), is(false)); + assertThat(capturedLog, not(containsString("retries remaining"))); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1)); } @@ -378,8 +375,7 @@ public void testInputStreamFailureExceptions() throws Exception { assertThat(e.getCause(), instanceOf(FileNotFoundException.class)); assertThat(e.getCause().getMessage(), containsString("hub4j-test-org-missing")); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(false)); - assertThat(capturedLog.contains("will try 1 more time"), is(false)); + assertThat(capturedLog, not(containsString("retries remaining"))); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1)); } @@ -394,8 +390,7 @@ public void testInputStreamFailureExceptions() throws Exception { .fetchHttpStatusCode(), equalTo(404)); String capturedLog = getTestCapturedLog(); - assertThat(capturedLog.contains("will try 2 more time"), is(false)); - assertThat(capturedLog.contains("will try 1 more time"), is(false)); + assertThat(capturedLog, not(containsString("retries remaining"))); assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1)); }