refactor(接口测试): Kubernetes client 超时时间设置

This commit is contained in:
fit2-zhao 2024-10-14 10:10:11 +08:00 committed by Craftsman
parent 2e65c15f12
commit 9b899ffb50
1 changed files with 5 additions and 0 deletions

View File

@ -30,12 +30,15 @@ public class KubernetesProvider {
private static final String RUNNING_PHASE = "Running"; private static final String RUNNING_PHASE = "Running";
private static final String SHELL_COMMAND = "sh"; private static final String SHELL_COMMAND = "sh";
private static final String LOCAL_URL = "http://127.0.0.1:8000"; private static final String LOCAL_URL = "http://127.0.0.1:8000";
private static final int TIMEOUT = 120000;
public static KubernetesClient getKubernetesClient(TestResourceDTO credential) { public static KubernetesClient getKubernetesClient(TestResourceDTO credential) {
ConfigBuilder configBuilder = new ConfigBuilder() ConfigBuilder configBuilder = new ConfigBuilder()
.withMasterUrl(credential.getIp()) .withMasterUrl(credential.getIp())
.withOauthToken(credential.getToken()) .withOauthToken(credential.getToken())
.withTrustCerts(true) .withTrustCerts(true)
.withConnectionTimeout(TIMEOUT) // 120秒连接超时
.withRequestTimeout(TIMEOUT) // 120秒请求超时
.withNamespace(credential.getNamespace()); .withNamespace(credential.getNamespace());
return new KubernetesClientBuilder() return new KubernetesClientBuilder()
@ -223,12 +226,14 @@ public class KubernetesProvider {
"-X POST -d '%s' " + "-X POST -d '%s' " +
"--connect-timeout %d " + "--connect-timeout %d " +
"--max-time %d " + "--max-time %d " +
"--retry-max-time %d" +
"--retry %d " + "--retry %d " +
"%s%s", "%s%s",
optToken, // otp-token optToken, // otp-token
JSON.toFormatJSONString(request), // 请求体 JSON.toFormatJSONString(request), // 请求体
30, // 连接超时 30, // 连接超时
120, // 最大时间 120, // 最大时间
3, // 最大重试时间
3, // 重试次数 3, // 重试次数
LOCAL_URL, // 本地 URL LOCAL_URL, // 本地 URL
path // 具体 API 路径 path // 具体 API 路径