From bf07e1748b1ac9de146355a4e96c55249995e533 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Tue, 6 Aug 2024 18:35:09 +0200 Subject: [PATCH] Fix once and for all the logging. Reduce parallelism --- .../sdktesting/infra/RestateDeployer.kt | 41 ++++++++++--------- .../dev/restate/sdktesting/junit/TestSuite.kt | 6 +-- .../kotlin/dev/restate/sdktesting/main.kt | 5 +++ src/main/resources/junit-platform.properties | 2 +- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/dev/restate/sdktesting/infra/RestateDeployer.kt b/src/main/kotlin/dev/restate/sdktesting/infra/RestateDeployer.kt index a29d44b..4a5869d 100644 --- a/src/main/kotlin/dev/restate/sdktesting/infra/RestateDeployer.kt +++ b/src/main/kotlin/dev/restate/sdktesting/infra/RestateDeployer.kt @@ -22,7 +22,6 @@ import java.nio.file.Path import java.util.concurrent.TimeUnit import org.apache.logging.log4j.LogManager import org.junit.jupiter.api.extension.ExtensionContext -import org.junit.jupiter.api.fail import org.rnorth.ducttape.unreliables.Unreliables import org.testcontainers.containers.* import org.testcontainers.containers.wait.strategy.Wait @@ -295,26 +294,28 @@ private constructor( waitRuntimeIngressHealthy() } - fun discoverDeployment(client: DeploymentApi, spec: ServiceSpec) { - Unreliables.retryUntilSuccess(5, TimeUnit.SECONDS) { - val url = spec.getEndpointUrl(config) - if (spec.skipRegistration) { - LOG.debug("Skipping registration for endpoint {}", url) - return@retryUntilSuccess - } - - val request = - RegisterDeploymentRequest( - RegisterDeploymentRequestAnyOf().uri(url.toString()).force(false)) - try { - val response = client.createDeployment(request) - LOG.debug("Successfully executed discovery for endpoint {}. Result: {}", url, response) - } catch (e: ApiException) { - fail( - "Error when discovering endpoint $url, got status code ${e.code} with body: ${e.responseBody}", - e) - } + private fun discoverDeployment(client: DeploymentApi, spec: ServiceSpec) { + val url = spec.getEndpointUrl(config) + if (spec.skipRegistration) { + LOG.debug("Skipping registration for endpoint {}", url) + return } + val request = + RegisterDeploymentRequest(RegisterDeploymentRequestAnyOf().uri(url.toString()).force(false)) + + val response = + Unreliables.retryUntilSuccess(20, TimeUnit.SECONDS) { + try { + return@retryUntilSuccess client.createDeployment(request) + } catch (e: ApiException) { + Thread.sleep(30) + throw IllegalStateException( + "Error when discovering endpoint $url, got status code ${e.code} with body: ${e.responseBody}", + e) + } + } + + LOG.debug("Successfully executed discovery for endpoint {}. Result: {}", url, response) } private fun writeEnvironmentReport(testReportDir: String) { diff --git a/src/main/kotlin/dev/restate/sdktesting/junit/TestSuite.kt b/src/main/kotlin/dev/restate/sdktesting/junit/TestSuite.kt index 5bb950d..ae3114a 100644 --- a/src/main/kotlin/dev/restate/sdktesting/junit/TestSuite.kt +++ b/src/main/kotlin/dev/restate/sdktesting/junit/TestSuite.kt @@ -46,13 +46,13 @@ class TestSuite( """ .trimMargin()) - // Apply additional runtime envs - registerGlobalConfig(getGlobalConfig().copy(additionalRuntimeEnvs = additionalEnvs)) - // Prepare Log4j2 configuration val log4j2Configuration = prepareLog4j2Config(reportDir, printToStdout) Configurator.reconfigure(log4j2Configuration) + // Apply additional runtime envs + registerGlobalConfig(getGlobalConfig().copy(additionalRuntimeEnvs = additionalEnvs)) + // Prepare launch request val request = LauncherDiscoveryRequestBuilder.request() diff --git a/src/main/kotlin/dev/restate/sdktesting/main.kt b/src/main/kotlin/dev/restate/sdktesting/main.kt index 57dd502..7e6a5eb 100644 --- a/src/main/kotlin/dev/restate/sdktesting/main.kt +++ b/src/main/kotlin/dev/restate/sdktesting/main.kt @@ -48,6 +48,11 @@ class RestateSdkTestSuite : CliktCommand() { override fun run() { // Disable log4j2 JMX, this prevents reconfiguration System.setProperty("log4j2.disable.jmx", "true") + // This is hours of debugging, don't touch it + // tl;dr this makes sure a single log4j2 configuration exists for the whole JVM, + // important to make Configurator.reconfigure work + System.setProperty( + "log4j2.contextSelector", "org.apache.logging.log4j.core.selector.BasicContextSelector") } } diff --git a/src/main/resources/junit-platform.properties b/src/main/resources/junit-platform.properties index 1ba7ded..cd3762a 100644 --- a/src/main/resources/junit-platform.properties +++ b/src/main/resources/junit-platform.properties @@ -11,4 +11,4 @@ junit.jupiter.execution.parallel.mode.default=same_thread # junit.jupiter.execution.parallel.mode.classes.default=concurrent # Automatically adjust parallelism based on available cpu/processor cores junit.jupiter.execution.parallel.config.strategy=dynamic -junit.jupiter.execution.parallel.config.dynamic.factor=1.5 \ No newline at end of file +junit.jupiter.execution.parallel.config.dynamic.factor=1.0 \ No newline at end of file