1h timeout on REST-call if running in debugger

This commit is contained in:
Michael Hoennig 2024-11-21 12:38:35 +01:00
parent b5b7f157ba
commit bdbee6a158

View File

@ -36,6 +36,7 @@ import java.util.function.Supplier;
import static java.net.URLEncoder.encode; import static java.net.URLEncoder.encode;
import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.DROP_COMMENTS; import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.KEEP_COMMENTS; import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.KEEP_COMMENTS;
import static net.hostsharing.hsadminng.test.DebuggerDetection.isDebuggerAttached;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.platform.commons.util.StringUtils.isBlank; import static org.junit.platform.commons.util.StringUtils.isBlank;
@ -151,7 +152,7 @@ public abstract class UseCase<T extends UseCase<?>> {
.GET() .GET()
.uri(new URI("http://localhost:" + testSuite.port + uriPath)) .uri(new URI("http://localhost:" + testSuite.port + uriPath))
.header("current-subject", ScenarioTest.RUN_AS_USER) .header("current-subject", ScenarioTest.RUN_AS_USER)
.timeout(Duration.ofSeconds(10)) .timeout(seconds(10))
.build(); .build();
final var response = client.send(request, BodyHandlers.ofString()); final var response = client.send(request, BodyHandlers.ofString());
return new HttpResponse(HttpMethod.GET, uriPath, null, response); return new HttpResponse(HttpMethod.GET, uriPath, null, response);
@ -166,7 +167,7 @@ public abstract class UseCase<T extends UseCase<?>> {
.uri(new URI("http://localhost:" + testSuite.port + uriPath)) .uri(new URI("http://localhost:" + testSuite.port + uriPath))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("current-subject", ScenarioTest.RUN_AS_USER) .header("current-subject", ScenarioTest.RUN_AS_USER)
.timeout(Duration.ofSeconds(10)) .timeout(seconds(10))
.build(); .build();
final var response = client.send(request, BodyHandlers.ofString()); final var response = client.send(request, BodyHandlers.ofString());
return new HttpResponse(HttpMethod.POST, uriPath, requestBody, response); return new HttpResponse(HttpMethod.POST, uriPath, requestBody, response);
@ -181,7 +182,7 @@ public abstract class UseCase<T extends UseCase<?>> {
.uri(new URI("http://localhost:" + testSuite.port + uriPath)) .uri(new URI("http://localhost:" + testSuite.port + uriPath))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("current-subject", ScenarioTest.RUN_AS_USER) .header("current-subject", ScenarioTest.RUN_AS_USER)
.timeout(Duration.ofSeconds(10)) .timeout(seconds(10))
.build(); .build();
final var response = client.send(request, BodyHandlers.ofString()); final var response = client.send(request, BodyHandlers.ofString());
return new HttpResponse(HttpMethod.PATCH, uriPath, requestBody, response); return new HttpResponse(HttpMethod.PATCH, uriPath, requestBody, response);
@ -195,7 +196,7 @@ public abstract class UseCase<T extends UseCase<?>> {
.uri(new URI("http://localhost:" + testSuite.port + uriPath)) .uri(new URI("http://localhost:" + testSuite.port + uriPath))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.header("current-subject", ScenarioTest.RUN_AS_USER) .header("current-subject", ScenarioTest.RUN_AS_USER)
.timeout(Duration.ofSeconds(10)) .timeout(seconds(10))
.build(); .build();
final var response = client.send(request, BodyHandlers.ofString()); final var response = client.send(request, BodyHandlers.ofString());
return new HttpResponse(HttpMethod.DELETE, uriPath, null, response); return new HttpResponse(HttpMethod.DELETE, uriPath, null, response);
@ -237,6 +238,10 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
} }
private static Duration seconds(final int secondsIfNoDebuggerAttached) {
return isDebuggerAttached() ? Duration.ofHours(1) : Duration.ofSeconds(secondsIfNoDebuggerAttached);
}
public final class HttpResponse { public final class HttpResponse {
@Getter @Getter