@@ -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}
0 commit comments