diff --git a/app/src/main/java/com/github/hoangqt/GitHub.java b/app/src/main/java/com/github/hoangqt/GitHub.java index de5a6e7..1285f28 100644 --- a/app/src/main/java/com/github/hoangqt/GitHub.java +++ b/app/src/main/java/com/github/hoangqt/GitHub.java @@ -3,6 +3,8 @@ import static io.restassured.RestAssured.given; import io.restassured.RestAssured; +import io.restassured.config.HttpClientConfig; +import io.restassured.config.RestAssuredConfig; import io.restassured.response.Response; public class GitHub { @@ -100,4 +102,26 @@ public Response updateIssue(String repo, String body, String issueNumber) { .when() .patch("/repos/{owner}/{repo}/issues/{issueNumber}"); } + + /** + * Sends a GET request to retrieve repositories from a GitHub repository with a customized timeout + * configuration. + * + * @param repo the name of the repository from which to fetch issues + * @return the response containing the issues or an error if the request fails + */ + public Response getSlowRequest(String repo) { + return given() + .config( + RestAssuredConfig.config() + .httpClient( + HttpClientConfig.httpClientConfig() + // Apache HttpClient settings in milliseconds + .setParam("http.connection.timeout", 5000) + .setParam("http.socket.timeout", 5000))) + .pathParam("owner", this.owner) + .pathParam("repo", repo) + .when() + .get("/repos/{owner}/{repo}"); + } } diff --git a/app/src/test/java/com/github/hoangqt/GitHubApiTest.java b/app/src/test/java/com/github/hoangqt/GitHubApiTest.java index 9634ff0..50175d1 100644 --- a/app/src/test/java/com/github/hoangqt/GitHubApiTest.java +++ b/app/src/test/java/com/github/hoangqt/GitHubApiTest.java @@ -140,6 +140,14 @@ public void testUpdateIssue() { assertThat(json.getString("labels")).containsAnyOf("bug", "invalid"); } + /** Example of a timeout configuration workaround to missing request cancellation feature. */ + @Test + public void testSlowRequest() { + var json = github.getSlowRequest(TEST_REPO).then().statusCode(200).extract().jsonPath(); + assertThat(json.getString("name")).isEqualTo(TEST_REPO); + assertThat(json.getString("owner.login")).isEqualTo(TEST_OWNER); + } + @Test public void testGetCommits() { var json =