From e43b79f3f5248597e22c2670dabf277d9925c510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Thu, 27 Jul 2023 20:28:27 +0200 Subject: [PATCH] test: Fix RemoteRegistryTest --- .../net/unix/rmi/RemoteRegistryTest.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/junixsocket-rmi/src/test/java/org/newsclub/net/unix/rmi/RemoteRegistryTest.java b/junixsocket-rmi/src/test/java/org/newsclub/net/unix/rmi/RemoteRegistryTest.java index 804b2cf45..4ea862391 100644 --- a/junixsocket-rmi/src/test/java/org/newsclub/net/unix/rmi/RemoteRegistryTest.java +++ b/junixsocket-rmi/src/test/java/org/newsclub/net/unix/rmi/RemoteRegistryTest.java @@ -126,22 +126,16 @@ protected int shutdownAfterSecs() { assertThrows(ServerException.class, () -> sra.getRegistry().getNaming().shutdownRegistry()); - sra.shutdownAndWait(true); + sra.shutdownAndWait(false); + if (!awaitNoRMIFiles(socketDir, 5)) { + sra.shutdownAndWait(true); + } } catch (Exception e) { throw e; } - int count; - int loops = 10; - do { - count = countRMIFiles(socketDir); - if (count == 0) { - break; - } - Thread.sleep(100); - } while (loops-- > 0); - - assertEquals(0, count, "There shouldn't be any RMI socket files in " + socketDir); + assertTrue(awaitNoRMIFiles(socketDir, 5), "There shouldn't be any RMI socket files in " + + socketDir); } finally { for (File d : socketDir.listFiles()) { d.delete(); @@ -150,6 +144,19 @@ protected int shutdownAfterSecs() { } } + private boolean awaitNoRMIFiles(File socketDir, int loops) throws InterruptedException { + int count; + do { + count = countRMIFiles(socketDir); + if (count == 0) { + return true; + } + Thread.sleep(100); + } while (loops-- > 0); + + return count == 0; + } + private void tryToSayHello(SpawnedRegistryAccess sra) throws Exception { AFRegistry registry = sra.getRegistry(); assertNotNull(registry, "Could not access the AFUNIXRegistry created by the forked VM");