Skip to content

Commit

Permalink
shorten 10s wait in test to 2s (#3214)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhizor committed Jun 3, 2021
1 parent 038b848 commit 34da86c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ public class AirbyteGithubStore {
private static final HttpClient httpClient = HttpClient.newHttpClient();

private final String baseUrl;
private final Duration timeout;

public static AirbyteGithubStore production() {
return new AirbyteGithubStore(GITHUB_BASE_URL);
return new AirbyteGithubStore(GITHUB_BASE_URL, Duration.ofSeconds(30));
}

public static AirbyteGithubStore test(String testBaseUrl) {
return new AirbyteGithubStore(testBaseUrl);
public static AirbyteGithubStore test(String testBaseUrl, Duration timeout) {
return new AirbyteGithubStore(testBaseUrl, timeout);
}

public AirbyteGithubStore(String baseUrl) {
public AirbyteGithubStore(String baseUrl, Duration timeout) {
this.baseUrl = baseUrl;
this.timeout = timeout;
}

public List<StandardDestinationDefinition> getLatestDestinations() throws IOException, InterruptedException {
Expand All @@ -75,7 +77,7 @@ public List<StandardSourceDefinition> getLatestSources() throws IOException, Int
String getFile(String filePathWithSlashPrefix) throws IOException, InterruptedException {
final var request = HttpRequest
.newBuilder(URI.create(baseUrl + filePathWithSlashPrefix))
.timeout(Duration.ofSeconds(1))
.timeout(timeout)
.header("accept", "*/*") // accept any file type
.build();
return httpClient.send(request, BodyHandlers.ofString()).body();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.IOException;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand All @@ -39,13 +40,15 @@

public class AirbyteGithubStoreTest {

private static final Duration TIMEOUT = Duration.ofSeconds(1);

private static MockWebServer webServer;
private static AirbyteGithubStore githubStore;

@BeforeAll
public static void setUp() {
webServer = new MockWebServer();
githubStore = AirbyteGithubStore.test(webServer.url("/").toString());
githubStore = AirbyteGithubStore.test(webServer.url("/").toString(), TIMEOUT);
}

@Nested
Expand All @@ -71,8 +74,8 @@ void testHttpTimeout() {
.addHeader("Content-Type", "text/plain; charset=utf-8")
.addHeader("Cache-Control", "no-cache")
.setBody("")
.setHeadersDelay(10, TimeUnit.SECONDS)
.setBodyDelay(10, TimeUnit.SECONDS);
.setHeadersDelay(TIMEOUT.toSeconds() * 2, TimeUnit.SECONDS)
.setBodyDelay(TIMEOUT.toSeconds() * 2, TimeUnit.SECONDS);
webServer.enqueue(timeoutResp);

assertThrows(HttpTimeoutException.class, () -> githubStore.getFile("test-file"));
Expand Down

0 comments on commit 34da86c

Please sign in to comment.