Skip to content

Commit

Permalink
SNOW-1739611: Verify timeouts are correctly set on http client
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Dec 12, 2024
1 parent d379857 commit fde1fee
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/test/java/net/snowflake/client/core/HttpUtilLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.net.SocketTimeoutException;
import java.time.Duration;
import net.snowflake.client.category.TestTags;
import org.apache.http.client.methods.Configurable;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -38,16 +40,29 @@ public void shouldOverrideConnectionAndSocketTimeouts() {
HttpUtil.setConnectionTimeout(100);
HttpUtil.setSocketTimeout(200);

assertEquals(Duration.ofMillis(100), HttpUtil.getConnectionTimeout());
assertEquals(Duration.ofMillis(200), HttpUtil.getSocketTimeout());

CloseableHttpClient httpClient =
HttpUtil.getHttpClient(new HttpClientSettingsKey(OCSPMode.INSECURE));

assertEquals(Duration.ofMillis(100), HttpUtil.getConnectionTimeout());
assertEquals(Duration.ofMillis(200), HttpUtil.getSocketTimeout());

assertEquals(100, ((Configurable) httpClient).getConfig().getConnectTimeout());
assertEquals(200, ((Configurable) httpClient).getConfig().getSocketTimeout());

try {
httpClient.execute(new HttpGet(HANG_WEBSERVER_ADDRESS));
fail("Request should fail with exception");
} catch (IOException e) {
MatcherAssert.assertThat(e, CoreMatchers.instanceOf(SocketTimeoutException.class));
} finally {
HttpUtil.setConnectionTimeout(60000);
HttpUtil.setSocketTimeout(300000);
}
}

@AfterEach
public void cleanup() {
HttpUtil.setConnectionTimeout(60000);
HttpUtil.setSocketTimeout(300000);
}
}

0 comments on commit fde1fee

Please sign in to comment.