Skip to content

Commit

Permalink
test: fixing UnreachableBackendTest
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoMlt authored and dmercuriali committed Dec 2, 2024
1 parent c5bfcb7 commit 79dc901
Showing 1 changed file with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.carapaceproxy.server.backends.BackendHealthStatus.Status.COLD;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
Expand All @@ -37,6 +38,7 @@
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.core.ProxyRequestsManager;
import org.carapaceproxy.server.backends.BackendHealthStatus;
import org.carapaceproxy.server.config.ActionConfiguration;
import org.carapaceproxy.server.config.NetworkListenerConfiguration;
import org.carapaceproxy.utils.RawHttpClient;
import org.carapaceproxy.utils.TestEndpointMapper;
Expand Down Expand Up @@ -98,7 +100,7 @@ public void testWithUnreachableBackend() throws Exception {
</html>
""", resp.getBodyString());
}
assertSame(server.getBackendHealthManager().getBackendStatus(key).getStatus(), BackendHealthStatus.Status.DOWN);
assertSame(BackendHealthStatus.Status.DOWN, server.getBackendHealthManager().getBackendStatus(key).getStatus());
assertThat((int) ProxyRequestsManager.PENDING_REQUESTS_GAUGE.get(), is(0));
}
}
Expand All @@ -117,6 +119,23 @@ public void testEmptyResponse() throws Exception {
try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.newFolder())) {
Properties properties = new Properties();
properties.put("healthmanager.tolerant", "true");
properties.put("backend.1.id", "backend-a");
properties.put("backend.1.enabled", "true");
properties.put("backend.1.host", "localhost");
properties.put("backend.1.port", String.valueOf(wireMockRule.port()));
properties.put("backend.1.probePath", "/");
properties.put("director.1.id", "director-1");
properties.put("director.1.backends", properties.getProperty("backend.1.id"));
properties.put("director.1.enabled", "true");
properties.put("action.1.id", "proxy-1");
properties.put("action.1.enabled", "true");
properties.put("action.1.type", ActionConfiguration.TYPE_PROXY);
properties.put("action.1.director", properties.getProperty("director.1.id"));
properties.put("route.100.id", "route-1");
properties.put("route.100.enabled", "true");
properties.put("route.100.match", "request.uri ~ \".*index.html.*\"");
properties.put("route.100.action", properties.getProperty("action.1.id"));
properties.put("healthmanager.tolerant", "true");
// configure resets all listeners configurations
server.configureAtBoot(new PropertiesConfigurationStore(properties));
server.addListener(new NetworkListenerConfiguration("localhost", 0));
Expand All @@ -136,7 +155,7 @@ public void testEmptyResponse() throws Exception {
</html>
""", resp.getBodyString());
}
assertSame(server.getBackendHealthManager().getBackendStatus(key).getStatus(), BackendHealthStatus.Status.COLD); // no troubles for new connections
assertSame(COLD, server.getBackendHealthManager().getBackendStatus(key).getStatus()); // no troubles for new connections
assertThat((int) ProxyRequestsManager.PENDING_REQUESTS_GAUGE.get(), is(0));
}
}
Expand Down Expand Up @@ -168,7 +187,7 @@ public void testConnectionResetByPeer() throws Exception {
</html>
""", resp.getBodyString());
}
assertSame(server.getBackendHealthManager().getBackendStatus(key).getStatus(), BackendHealthStatus.Status.COLD); // no troubles for new connections
assertSame(COLD, server.getBackendHealthManager().getBackendStatus(key).getStatus()); // no troubles for new connections
assertThat((int) ProxyRequestsManager.PENDING_REQUESTS_GAUGE.get(), is(0));
}
}
Expand All @@ -186,6 +205,23 @@ public void testNonHttpResponseThenClose() throws Exception {
try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.newFolder())) {
Properties properties = new Properties();
properties.put("healthmanager.tolerant", "true");
properties.put("backend.1.id", "backend-a");
properties.put("backend.1.enabled", "true");
properties.put("backend.1.host", "localhost");
properties.put("backend.1.port", String.valueOf(wireMockRule.port()));
properties.put("backend.1.probePath", "/");
properties.put("director.1.id", "director-1");
properties.put("director.1.backends", properties.getProperty("backend.1.id"));
properties.put("director.1.enabled", "true");
properties.put("action.1.id", "proxy-1");
properties.put("action.1.enabled", "true");
properties.put("action.1.type", ActionConfiguration.TYPE_PROXY);
properties.put("action.1.director", properties.getProperty("director.1.id"));
properties.put("route.100.id", "route-1");
properties.put("route.100.enabled", "true");
properties.put("route.100.match", "request.uri ~ \".*index.html.*\"");
properties.put("route.100.action", properties.getProperty("action.1.id"));
properties.put("healthmanager.tolerant", "true");
server.configureAtBoot(new PropertiesConfigurationStore(properties));
server.addListener(new NetworkListenerConfiguration("localhost", 0));
server.start();
Expand All @@ -204,7 +240,7 @@ public void testNonHttpResponseThenClose() throws Exception {
</html>
""", resp.getBodyString());
}
assertSame(server.getBackendHealthManager().getBackendStatus(key).getStatus(), BackendHealthStatus.Status.COLD);
assertSame(COLD, server.getBackendHealthManager().getBackendStatus(key).getStatus());
assertThat((int) ProxyRequestsManager.PENDING_REQUESTS_GAUGE.get(), is(0));
}
}
Expand Down

0 comments on commit 79dc901

Please sign in to comment.