Skip to content

Commit

Permalink
test: fix flaky version checker test by using simpler mock (#7863)
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra authored and Zara Lim committed Nov 22, 2021
1 parent e95ff38 commit d2612c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
24 changes: 2 additions & 22 deletions ksqldb-version-metrics-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@
</dependency>

<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.4</version>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -78,19 +71,6 @@
<version>${apache.httpcomponents.version}</version>
</dependency>

<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>3.10.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,37 @@

package io.confluent.ksql.version.metrics;

import static org.mockserver.model.HttpRequest.request;

import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import io.confluent.ksql.version.metrics.collector.KsqlModuleType;
import io.confluent.support.metrics.BaseSupportConfig;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.kafka.test.TestUtils;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.mockserver.integration.ClientAndProxy;
import org.mockserver.socket.PortFactory;

public class VersionCheckerIntegrationTest {

private static int proxyPort;
private static ClientAndProxy clientAndProxy;

@Rule
public final Timeout timeout = Timeout.builder()
.withTimeout(30, TimeUnit.SECONDS)
.withLookingForStuckThread(true)
.build();

@BeforeClass
public static void startProxy() {
proxyPort = PortFactory.findFreePort();
clientAndProxy = ClientAndProxy.startClientAndProxy(proxyPort);
}

@Rule
public WireMockRule wireMockRule = new WireMockRule(
WireMockConfiguration.wireMockConfig()
.dynamicPort()
);

@Test
public void testMetricsAgent() throws InterruptedException {
WireMock.stubFor(WireMock.post("/ksql/anon").willReturn(WireMock.ok()));

final KsqlVersionCheckerAgent versionCheckerAgent = new KsqlVersionCheckerAgent(
() -> false
Expand All @@ -57,13 +55,13 @@ public void testMetricsAgent() throws InterruptedException {
.CONFLUENT_SUPPORT_METRICS_ENDPOINT_SECURE_ENABLE_CONFIG, "false");
versionCheckProps.setProperty(
BaseSupportConfig.CONFLUENT_SUPPORT_PROXY_CONFIG,
"http://localhost:" + proxyPort
"http://localhost:" + wireMockRule.port()
);
versionCheckerAgent.start(KsqlModuleType.SERVER, versionCheckProps);

TestUtils.waitForCondition(() -> {
try {
clientAndProxy.verify(request().withPath("/ksql/anon").withMethod("POST"));
WireMock.verify(WireMock.postRequestedFor(WireMock.urlPathEqualTo("/ksql/anon")));
return true;
} catch (final AssertionError e) {
return false;
Expand Down

0 comments on commit d2612c0

Please sign in to comment.