Skip to content

Commit e8e79cf

Browse files
committed
Fix public path + fixes to tests
1 parent 99f3d6a commit e8e79cf

6 files changed

Lines changed: 26 additions & 28 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/api/ProxyController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public ResponseEntity<ApiResponse<Proxy>> startProxy(@PathVariable String proxyS
269269
}
270270

271271
private String getPublicPath(String proxyId) {
272-
return contextPathHelper.withEndingSlash() + "api/route/" + proxyId;
272+
return contextPathHelper.withEndingSlash() + "api/route/" + proxyId + "/";
273273
}
274274

275275
public static class ParametersBody {

src/main/java/eu/openanalytics/containerproxy/util/Retrying.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static boolean retry(Attempt job, int maxDelay, boolean retryOnException)
3737

3838
public static boolean retry(Attempt job, int maxDelay, String logMessage, int logAfterAttmepts, boolean retryOnException) {
3939
boolean retVal = false;
40-
RuntimeException exception = null;
40+
Exception exception = null;
4141
int maxAttempts = numberOfAttempts(maxDelay);
4242
for (int currentAttempt = 0; currentAttempt < maxAttempts; currentAttempt++) {
4343
delay(currentAttempt); // delay here so that we don't delay for the last iteration
@@ -47,16 +47,16 @@ public static boolean retry(Attempt job, int maxDelay, String logMessage, int lo
4747
exception = null;
4848
break;
4949
}
50-
} catch (RuntimeException e) {
50+
} catch (Exception e) {
5151
if (retryOnException) exception = e;
52-
else throw e;
52+
else throw new RuntimeException(e);
5353
}
5454
if (currentAttempt > logAfterAttmepts && logMessage != null) {
5555
log.info(String.format("Retry: %s (%d/%d)", logMessage, currentAttempt, maxAttempts));
5656
}
5757
}
5858
if (exception == null) return retVal;
59-
else throw exception;
59+
else throw new RuntimeException(exception);
6060
}
6161

6262
public static void delay(Integer attempt) {
@@ -84,7 +84,7 @@ public static int numberOfAttempts(Integer maxDelay) {
8484

8585
@FunctionalInterface
8686
public interface Attempt {
87-
boolean attempt(int currentAttempt, int maxAttempts);
87+
boolean attempt(int currentAttempt, int maxAttempts) throws Exception;
8888
}
8989

9090
}

src/test/java/eu/openanalytics/containerproxy/test/helpers/NotInternalOnlyTestStrategy.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import eu.openanalytics.containerproxy.backend.strategy.IProxyTestStrategy;
2424
import eu.openanalytics.containerproxy.model.runtime.Proxy;
25-
import eu.openanalytics.containerproxy.service.StructuredLogger;
2625
import eu.openanalytics.containerproxy.util.Retrying;
2726

2827
import java.net.HttpURLConnection;
@@ -32,31 +31,24 @@
3231

3332
public class NotInternalOnlyTestStrategy implements IProxyTestStrategy {
3433

35-
private final StructuredLogger log = StructuredLogger.create(getClass());
36-
3734
@Override
3835
public boolean testProxy(Proxy proxy) {
3936
URI targetURI = proxy.getTargets().get("");
4037

4138
return Retrying.retry((currentAttempt, maxAttempts) -> {
42-
try {
43-
if (proxy.getStatus().isUnavailable()) {
44-
// proxy got stopped while loading -> no need to try to connect it since the container will already be deleted
45-
return true;
46-
}
47-
URL testURL = new URL(targetURI.toString() + "/");
48-
HttpURLConnection connection = ((HttpURLConnection) testURL.openConnection());
49-
connection.setInstanceFollowRedirects(false);
50-
int responseCode = connection.getResponseCode();
51-
if (Arrays.asList(200, 301, 302, 303, 307, 308).contains(responseCode)) {
52-
return true;
53-
}
54-
log.warn(proxy, "Error during test strategy test: status code: " + responseCode);
55-
} catch (Exception e) {
56-
return false;
39+
if (proxy.getStatus().isUnavailable()) {
40+
// proxy got stopped while loading -> no need to try to connect it since the container will already be deleted
41+
return true;
42+
}
43+
URL testURL = new URL(targetURI.toString() + "/");
44+
HttpURLConnection connection = ((HttpURLConnection) testURL.openConnection());
45+
connection.setInstanceFollowRedirects(false);
46+
int responseCode = connection.getResponseCode();
47+
if (Arrays.asList(200, 301, 302, 303, 307, 308).contains(responseCode)) {
48+
return true;
5749
}
5850
return false;
59-
}, 60_000);
51+
}, 60_000, "Container unresponsive", 10, true);
6052
}
6153

6254
}

src/test/java/eu/openanalytics/containerproxy/test/proxy/TestIntegrationOnEcs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void launchProxy() {
116116
Assertions.assertEquals(3, environment.size());
117117
Assertions.assertEquals("demo", environment.get("SHINYPROXY_USERNAME"));
118118
Assertions.assertEquals("", environment.get("SHINYPROXY_USERGROUPS"));
119-
Assertions.assertEquals("/api/route/" + proxy.getId(), environment.get("SHINYPROXY_PUBLIC_PATH")); // TODO no ending slash?
119+
Assertions.assertEquals("/api/route/" + proxy.getId() + "/", environment.get("SHINYPROXY_PUBLIC_PATH"));
120120
Assertions.assertEquals("openanalytics/shinyproxy-integration-test-app", containerDefinition.image());
121121
Assertions.assertNull(containerDefinition.privileged()); // fargate does not support privileged
122122
Assertions.assertNull(containerDefinition.hostname());

src/test/java/eu/openanalytics/containerproxy/test/proxy/TestIntegrationOnKube.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public void launchProxyWithEnv() {
190190
Assertions.assertEquals("VALUE2", env.get("VAR2").getValue());
191191
Assertions.assertTrue(env.containsKey("VAR3"));
192192
Assertions.assertEquals("VALUE3", env.get("VAR3").getValue());
193+
Assertions.assertEquals("/api/route/" + proxy.getId() + "/", env.get("SHINYPROXY_PUBLIC_PATH").getValue());
193194

194195
inst.proxyService.stopProxy(null, proxy, true).run();
195196

src/test/java/eu/openanalytics/containerproxy/test/proxy/TestIntegrationProxySharing.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ public void testCleanupPendingDelegateProxies(String backend, Map<String, String
345345

346346
// wait for scale-up to finish
347347
// pending proxy should be marked as ToRemove
348-
waitUntilNumberOfDelegateProxies(inst, 2, 1, 0, 1);
348+
// wait for long time, leader election can take long
349+
waitUntilNumberOfDelegateProxies(inst, 2, 1, 0, 1, 120_000);
349350

350351
// cleanup should remove old proxy
351352
proxySharingScaler.enableCleanup();
@@ -622,14 +623,18 @@ private void waitUntilNumberOfDelegateProxies(ShinyProxyInstance inst, int numDe
622623
}
623624

624625
private void waitUntilNumberOfDelegateProxies(ShinyProxyInstance inst, int numDelegateProxies, int numAvailable, int numPending, int numRemove) {
626+
waitUntilNumberOfDelegateProxies(inst, numDelegateProxies, numAvailable, numPending, numRemove, 60_000);
627+
}
628+
629+
private void waitUntilNumberOfDelegateProxies(ShinyProxyInstance inst, int numDelegateProxies, int numAvailable, int numPending, int numRemove, int delay) {
625630
TestProxySharingScaler proxySharingScaler = inst.getBean("proxySharingScaler_myApp", TestProxySharingScaler.class);
626631
IDelegateProxyStore delegateProxyStore = proxySharingScaler.getDelegateProxyStore();
627632
boolean noPendingSeats = Retrying.retry((c, m) -> {
628633
return delegateProxyStore.getAllDelegateProxies().size() == numDelegateProxies
629634
&& delegateProxyStore.getAllDelegateProxies(DelegateProxyStatus.Available).count() == numAvailable
630635
&& delegateProxyStore.getAllDelegateProxies(DelegateProxyStatus.Pending).count() == numPending
631636
&& delegateProxyStore.getAllDelegateProxies(DelegateProxyStatus.ToRemove).count() == numRemove;
632-
}, 90_000, "assert number delegated proxies", 1, true);
637+
}, 120_000, "assert number delegated proxies", 1, true);
633638
Assertions.assertTrue(noPendingSeats,
634639
String.format("Total: %s, Available: %s, Pending: %s, ToRemove: %s",
635640
delegateProxyStore.getAllDelegateProxies().size(),

0 commit comments

Comments
 (0)