diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2023-03-31 13:28:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 13:28:49 +0200 |
commit | f64e823e6be0d5e0766296e776c29e27fa8fca21 (patch) | |
tree | 82c27f3ff86e979fd3df63be6ac9085aab6fb219 | |
parent | 9f18e31a39d6c30349509d7d192bd36ddbe41e3f (diff) | |
parent | 7043dfcbb92f934d3a1c99ffdf4dd2abf0f2bea3 (diff) |
Merge pull request #26659 from vespa-engine/jonmv/debug-flaky-test
Restructure assertions and reduce inner timeout, so we see all errors
-rw-r--r-- | vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java index 9195b5ab858..cf9a36f2aa8 100644 --- a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java +++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/ApacheClusterTest.java @@ -35,7 +35,7 @@ class ApacheClusterTest { final WireMockExtension server = new WireMockExtension(); @Test - void testClient() throws IOException, ExecutionException, InterruptedException, TimeoutException { + void testClient() throws Exception { for (Compression compression : Compression.values()) { try (ApacheCluster cluster = new ApacheCluster(new FeedClientBuilderImpl(List.of(URI.create("http://localhost:" + server.port()))) .setCompression(compression))) { @@ -48,25 +48,28 @@ class ApacheClusterTest { Map.of("name1", () -> "value1", "name2", () -> "value2"), "content".getBytes(UTF_8), - Duration.ofSeconds(20)), + Duration.ofSeconds(10)), vessel); - HttpResponse response = vessel.get(15, TimeUnit.SECONDS); - assertEquals("{}", new String(response.body(), UTF_8)); - assertEquals(200, response.code()); - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - try (OutputStream zip = new GZIPOutputStream(buffer)) { zip.write("content".getBytes(UTF_8)); } - server.verify(1, anyRequestedFor(anyUrl())); - RequestPatternBuilder expected = postRequestedFor(urlEqualTo("/path")).withHeader("name1", equalTo("value1")) - .withHeader("name2", equalTo("value2")) - .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) - .withRequestBody(equalTo("content")); - expected = switch (compression) { - case auto, none -> expected.withoutHeader("Content-Encoding"); - case gzip -> expected.withHeader("Content-Encoding", equalTo("gzip")); + AutoCloseable verifyResponse = () -> { + HttpResponse response = vessel.get(15, TimeUnit.SECONDS); + assertEquals("{}", new String(response.body(), UTF_8)); + assertEquals(200, response.code()); }; - server.verify(1, expected); - server.resetRequests(); + AutoCloseable verifyServer = () -> { + server.verify(1, anyRequestedFor(anyUrl())); + RequestPatternBuilder expected = postRequestedFor(urlEqualTo("/path")).withHeader("name1", equalTo("value1")) + .withHeader("name2", equalTo("value2")) + .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) + .withRequestBody(equalTo("content")); + expected = switch (compression) { + case auto, none -> expected.withoutHeader("Content-Encoding"); + case gzip -> expected.withHeader("Content-Encoding", equalTo("gzip")); + }; + server.verify(1, expected); + server.resetRequests(); + }; + try (verifyServer; verifyResponse) { } } } } |