Skip to content

Commit 8c73969

Browse files
committed
Ref #29447: improve tests
1 parent d4bcf07 commit 8c73969

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/backend/dispatcher/proxysharing/ProxySharingScaler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private void reconcile() {
289289
} else if ((num - specExtension.minimumSeatsAvailable) >= specExtension.seatsPerContainer) {
290290
long numToScaleDown = (num - specExtension.minimumSeatsAvailable) / specExtension.seatsPerContainer;
291291
if (numToScaleDown <= 0) {
292-
throw new IllegalStateException("oops");
292+
return;
293293
}
294294
if (lastScaleUp != null) {
295295
long scaleUpDeltaMinutes = Duration.between(lastScaleUp, Instant.now()).toMinutes();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ public void enableCleanup() {
4444
@Override
4545
protected void cleanup() {
4646
if (cleanup) {
47-
System.out.println("Doing cleanup");
4847
super.cleanup();
49-
} else {
50-
System.out.println("Skipping cleanup");
5148
}
5249
}
5350

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public void testSetPublicPathPrefix(String backend, Map<String, String> properti
157157

158158
inst.client.stopProxy(id);
159159
}
160+
} finally {
161+
ProxySharingScaler.setPublicPathPrefix("/api/route/");
160162
}
161163
}
162164

@@ -271,6 +273,7 @@ public void testConfigChange(String backend, Map<String, String> properties) {
271273
// launch an instance and app
272274
String oldAppId;
273275
try (ShinyProxyInstance inst = new ShinyProxyInstance("application-test-pre-initialization-redis-1.yml", properties, true)) {
276+
TestProxySharingScaler proxySharingScaler = inst.getBean("proxySharingScaler_myApp", TestProxySharingScaler.class);
274277
oldAppId = inst.client.startProxy("myApp");
275278
Proxy proxy = inst.proxyService.getProxy(oldAppId);
276279
inst.client.testProxyReachable(proxy.getTargetId());
@@ -281,6 +284,8 @@ public void testConfigChange(String backend, Map<String, String> properties) {
281284
Assertions.assertEquals(proxy.getTargetId(), proxy.getRuntimeValue(TargetIdKey.inst));
282285
Assertions.assertNotNull(proxy.getRuntimeValue(SeatIdKey.inst));
283286

287+
// wait for scale-up to finish
288+
waitUntilNumberOfAvailableDelegateProxies(proxySharingScaler, 2);
284289
}
285290
// re-start instance with updated app config
286291
try (ShinyProxyInstance inst = new ShinyProxyInstance("application-test-pre-initialization-redis-2.yml", properties, true)) {
@@ -295,9 +300,11 @@ public void testConfigChange(String backend, Map<String, String> properties) {
295300
// old app should still be reachable
296301
inst.client.testProxyReachable(proxy.getTargetId());
297302

303+
// wait until app is marked to be removed
304+
waitUntilDelegateProxyIsToRemove(proxySharingScaler, proxy.getTargetId());
298305
DelegateProxy delegateProxy = delegateProxyStore.getDelegateProxy(proxy.getTargetId());
299306
Assertions.assertEquals(DelegateProxyStatus.ToRemove, delegateProxy.getDelegateProxyStatus());
300-
Assertions.assertEquals("641fead76e0c432d0ae258a9745bcf69eac7b3c3", delegateProxy.getProxySpecHash());
307+
Assertions.assertEquals("fcbf978730e85a8517eaa6812ace9bbd08acad1b", delegateProxy.getProxySpecHash());
301308

302309
// should create new instance with new hash
303310
waitUntilNumberOfDelegateProxies(proxySharingScaler, 3);
@@ -310,19 +317,20 @@ public void testConfigChange(String backend, Map<String, String> properties) {
310317

311318
// a second DelegateProxy with old config should exist in DelegateProxyStore
312319
Optional<DelegateProxy> secondDelegateProxy = delegateProxyStore.getAllDelegateProxies().stream()
313-
.filter(it -> it.getProxySpecHash().equals("641fead76e0c432d0ae258a9745bcf69eac7b3c3") && !it.getProxy().getId().equals(proxy.getTargetId()))
320+
.filter(it -> it.getProxySpecHash().equals("fcbf978730e85a8517eaa6812ace9bbd08acad1b") && !it.getProxy().getId().equals(proxy.getTargetId()))
314321
.findFirst();
315322
Assertions.assertTrue(secondDelegateProxy.isPresent());
316323
Assertions.assertEquals(DelegateProxyStatus.ToRemove, secondDelegateProxy.get().getDelegateProxyStatus());
317324

318325
// a DelegateProxy with new config should exist in DelegateProxyStore
319326
Optional<DelegateProxy> newDelegateProxy = delegateProxyStore.getAllDelegateProxies().stream()
320-
.filter(it -> !it.getProxySpecHash().equals("641fead76e0c432d0ae258a9745bcf69eac7b3c3"))
327+
.filter(it -> !it.getProxySpecHash().equals("fcbf978730e85a8517eaa6812ace9bbd08acad1b"))
321328
.findFirst();
322329
Assertions.assertTrue(newDelegateProxy.isPresent());
323330
waitUntilDelegateProxyIsAvailable(proxySharingScaler, newDelegateProxy.get().getProxy().getId());
324-
Assertions.assertEquals(DelegateProxyStatus.Available, newDelegateProxy.get().getDelegateProxyStatus());
325-
Assertions.assertEquals("b21e966c35c7689f465f06722b13ec28cead0e33", newDelegateProxy.get().getProxySpecHash());
331+
DelegateProxy newDelegateProxy2 = delegateProxyStore.getDelegateProxy(newDelegateProxy.get().getProxy().getId());
332+
Assertions.assertEquals(DelegateProxyStatus.Available, newDelegateProxy2.getDelegateProxyStatus());
333+
Assertions.assertEquals("ac5969e6d722a0951143ba125846feeff4491b33", newDelegateProxy2.getProxySpecHash());
326334

327335
// stop running app
328336
inst.client.stopProxy(oldAppId);
@@ -331,9 +339,9 @@ public void testConfigChange(String backend, Map<String, String> properties) {
331339

332340
// proxies with old version should get cleaned up
333341
waitUntilNumberOfDelegateProxies(proxySharingScaler, 1);
334-
DelegateProxy newDelegateProxy2 = delegateProxyStore.getAllDelegateProxies().stream().findFirst().get();
335-
Assertions.assertEquals(newDelegateProxy.get().getProxy().getId(), newDelegateProxy2.getProxy().getId());
336-
Assertions.assertEquals("b21e966c35c7689f465f06722b13ec28cead0e33", newDelegateProxy2.getProxySpecHash());
342+
DelegateProxy newDelegateProxy3 = delegateProxyStore.getAllDelegateProxies().stream().findFirst().get();
343+
Assertions.assertEquals(newDelegateProxy.get().getProxy().getId(), newDelegateProxy3.getProxy().getId());
344+
Assertions.assertEquals("ac5969e6d722a0951143ba125846feeff4491b33", newDelegateProxy3.getProxySpecHash());
337345
}
338346
}
339347
}
@@ -342,6 +350,8 @@ public void testConfigChange(String backend, Map<String, String> properties) {
342350
// TODO test scaleDownDelay
343351
// TODO test multiple seats
344352
// TODO test DelegateProxy structure
353+
// TODO test cleanup pending delegateproxy
354+
// TODO test seat timeout
345355

346356
private void waitUntilNoPendingSeats(ProxySharingScaler proxySharingScaler) {
347357
boolean noPendingSeats = Retrying.retry((c, m) -> {
@@ -364,11 +374,26 @@ private void waitUntilNumberOfDelegateProxies(TestProxySharingScaler proxySharin
364374
Assertions.assertTrue(noPendingSeats);
365375
}
366376

377+
private void waitUntilNumberOfAvailableDelegateProxies(TestProxySharingScaler proxySharingScaler, int numSeats) {
378+
boolean noPendingSeats = Retrying.retry((c, m) -> {
379+
return proxySharingScaler.getDelegateProxyStore().getAllDelegateProxies().size() == numSeats &&
380+
proxySharingScaler.getDelegateProxyStore().getAllDelegateProxies().stream().allMatch(it -> it.getDelegateProxyStatus().equals(DelegateProxyStatus.Available));
381+
}, 60_000, "assert number delegated proxies", 1, true);
382+
Assertions.assertTrue(noPendingSeats);
383+
}
384+
367385
private void waitUntilDelegateProxyIsAvailable(TestProxySharingScaler proxySharingScaler, String delegateProxyId) {
368386
boolean noPendingSeats = Retrying.retry((c, m) -> {
369387
return proxySharingScaler.getDelegateProxyStore().getDelegateProxy(delegateProxyId).getDelegateProxyStatus() == DelegateProxyStatus.Available;
370388
}, 60_000, "assert number delegated proxies", 1, true);
371389
Assertions.assertTrue(noPendingSeats);
372390
}
373391

392+
private void waitUntilDelegateProxyIsToRemove(TestProxySharingScaler proxySharingScaler, String delegateProxyId) {
393+
boolean noPendingSeats = Retrying.retry((c, m) -> {
394+
return proxySharingScaler.getDelegateProxyStore().getDelegateProxy(delegateProxyId).getDelegateProxyStatus() == DelegateProxyStatus.ToRemove;
395+
}, 60_000, "assert number delegated proxies", 1, true);
396+
Assertions.assertTrue(noPendingSeats);
397+
}
398+
374399
}

src/test/resources/application-test-pre-initialization-redis-1.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ proxy:
2828

2929
specs:
3030
- id: myApp
31-
minimum-seats-available: 1
31+
minimum-seats-available: 3
32+
seats-per-container: 3
3233
container-specs:
3334
- image: "openanalytics/shinyproxy-integration-test-app"
3435
cmd: [ "R", "-e", "shinyproxy::run_01_hello()" ]

src/test/resources/application-test-pre-initialization-redis-2.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ proxy:
2929
specs:
3030
- id: myApp
3131
display-name: myUpdatedDisplayName
32-
minimum-seats-available: 1
32+
minimum-seats-available: 3
33+
seats-per-container: 3
3334
container-specs:
3435
- image: "openanalytics/shinyproxy-integration-test-app"
3536
cmd: [ "R", "-e", "shinyproxy::run_01_hello()" ]

0 commit comments

Comments
 (0)